From c9a546b73b20243a02941a4cef93f2bbf524b1a2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 16 Jun 2015 18:18:55 +0100 Subject: [PATCH] Load all components* through a central broker so we can overrride them with different ones * only one place actually uses it currently --- src/ComponentBroker.js | 40 ++++++++++++++++++++++++++++++++++++++++ src/pages/MatrixChat.js | 11 +++++++---- 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/ComponentBroker.js diff --git a/src/ComponentBroker.js b/src/ComponentBroker.js new file mode 100644 index 0000000000..ea17d19bee --- /dev/null +++ b/src/ComponentBroker.js @@ -0,0 +1,40 @@ +var components = {}; + +function load(name) { + var types = [ + 'atoms', + 'molecules', + 'organisms', + 'templates', + 'pages' + ]; + var ex = null; + for (var i = 0; i < types.length; ++i) { + try { + var module = require("./"+types[i]+"/"+name); + components[name] = module; + return module; + } catch (err) { + ex = err; + } + } + throw ex; +}; + +module.exports = { + get: function(name) { + if (components[name]) return components[name]; + + components[name] = load(name); + return components[name]; + }, + + set: function(name, module) { + components[name] = module; + } +}; + +require('./organisms/RoomList'); +require('./organisms/RoomView'); +require('./molecules/MatrixToolbar'); +require('./templates/Login'); diff --git a/src/pages/MatrixChat.js b/src/pages/MatrixChat.js index 5327031acc..1e388b7d5c 100644 --- a/src/pages/MatrixChat.js +++ b/src/pages/MatrixChat.js @@ -1,11 +1,14 @@ var React = require('react'); +var ComponentBroker = require('../ComponentBroker'); -var RoomList = require('../organisms/RoomList'); -var RoomView = require('../organisms/RoomView'); -var MatrixToolbar = require('../molecules/MatrixToolbar'); +var RoomList = ComponentBroker.get('RoomList'); +var RoomView = ComponentBroker.get('RoomView'); +var MatrixToolbar = ComponentBroker.get('MatrixToolbar'); +var Login = ComponentBroker.get('Login'); + +// should be atomised var Loader = require("react-loader"); -var Login = require('../templates/Login'); var mxCliPeg = require("../MatrixClientPeg");