diff --git a/src/ComponentBroker.js b/src/ComponentBroker.js index ea17d19b..f3670bf6 100644 --- a/src/ComponentBroker.js +++ b/src/ComponentBroker.js @@ -1,24 +1,9 @@ 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; + var module = require("./"+name); + components[name] = module; + return module; }; module.exports = { @@ -34,7 +19,21 @@ module.exports = { } }; +// Statically require all the components we know about, +// otherwise browserify has no way of knowing what module to include +// Must be in this file (because the require is file-specific) and +// must be at the end because the components include this file. +require('./atoms/LogoutButton'); +require('./atoms/MessageTimestamp'); +require('./molecules/MatrixToolbar'); +require('./molecules/RoomTile'); +require('./molecules/MessageTile'); +require('./molecules/SenderProfile'); +require('./molecules/UnknownMessageTile'); +require('./molecules/MTextTile'); +require('./molecules/MEmoteTile'); +require('./molecules/RoomHeader'); +require('./molecules/MessageComposer'); require('./organisms/RoomList'); require('./organisms/RoomView'); -require('./molecules/MatrixToolbar'); require('./templates/Login'); diff --git a/src/molecules/MatrixToolbar.js b/src/molecules/MatrixToolbar.js index e6b336aa..f4b5ba1a 100644 --- a/src/molecules/MatrixToolbar.js +++ b/src/molecules/MatrixToolbar.js @@ -1,6 +1,8 @@ var React = require('react'); -var LogoutButton = require("../atoms/LogoutButton"); +var ComponentBroker = require('../ComponentBroker'); + +var LogoutButton = ComponentBroker.get("atoms/LogoutButton"); module.exports = React.createClass({ render: function() { diff --git a/src/molecules/MessageTile.js b/src/molecules/MessageTile.js index dd1ab38f..8207f743 100644 --- a/src/molecules/MessageTile.js +++ b/src/molecules/MessageTile.js @@ -1,13 +1,15 @@ var React = require('react'); -var MessageTimestamp = require('../atoms/MessageTimestamp'); -var SenderProfile = require('../molecules/SenderProfile'); +var ComponentBroker = require('../ComponentBroker'); -var UnknownMessageTile = require('../molecules/UnknownMessageTile'); +var MessageTimestamp = ComponentBroker.get('atoms/MessageTimestamp'); +var SenderProfile = ComponentBroker.get('molecules/SenderProfile'); + +var UnknownMessageTile = ComponentBroker.get('molecules/UnknownMessageTile'); var tileTypes = { - 'm.text': require('../molecules/MTextTile'), - 'm.emote': require('../molecules/MEmoteTile') + 'm.text': ComponentBroker.get('molecules/MTextTile'), + 'm.emote': ComponentBroker.get('molecules/MEmoteTile') }; module.exports = React.createClass({ diff --git a/src/organisms/RoomList.js b/src/organisms/RoomList.js index 56b07508..45dd7001 100644 --- a/src/organisms/RoomList.js +++ b/src/organisms/RoomList.js @@ -1,8 +1,9 @@ var React = require('react'); var MatrixClientPeg = require("../MatrixClientPeg"); +var ComponentBroker = require('../ComponentBroker'); -var RoomTile = require("../molecules/RoomTile"); +var RoomTile = ComponentBroker.get("molecules/RoomTile"); module.exports = React.createClass({ componentWillMount: function() { diff --git a/src/organisms/RoomView.js b/src/organisms/RoomView.js index 7b4e9a4b..8422ac49 100644 --- a/src/organisms/RoomView.js +++ b/src/organisms/RoomView.js @@ -1,9 +1,12 @@ var React = require('react'); -var MessageTile = require('../molecules/MessageTile'); -var RoomHeader = require('../molecules/RoomHeader'); -var MessageComposer = require('../molecules/MessageComposer'); var MatrixClientPeg = require("../MatrixClientPeg"); +var ComponentBroker = require('../ComponentBroker'); + +var MessageTile = ComponentBroker.get('molecules/MessageTile'); +var RoomHeader = ComponentBroker.get('molecules/RoomHeader'); +var MessageComposer = ComponentBroker.get('molecules/MessageComposer'); + module.exports = React.createClass({ getInitialState: function() { diff --git a/src/pages/MatrixChat.js b/src/pages/MatrixChat.js index 1e388b7d..12b49af6 100644 --- a/src/pages/MatrixChat.js +++ b/src/pages/MatrixChat.js @@ -1,10 +1,10 @@ var React = require('react'); var ComponentBroker = require('../ComponentBroker'); -var RoomList = ComponentBroker.get('RoomList'); -var RoomView = ComponentBroker.get('RoomView'); -var MatrixToolbar = ComponentBroker.get('MatrixToolbar'); -var Login = ComponentBroker.get('Login'); +var RoomList = ComponentBroker.get('organisms/RoomList'); +var RoomView = ComponentBroker.get('organisms/RoomView'); +var MatrixToolbar = ComponentBroker.get('molecules/MatrixToolbar'); +var Login = ComponentBroker.get('templates/Login'); // should be atomised var Loader = require("react-loader");