From 2abea931cada00fc22be45790255d0cfee3e2d15 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 19 Jun 2015 12:53:48 +0100 Subject: [PATCH] Split out render methods into 'views' leaving UI logic in 'controllers'. Hopefully should make it easier to skin / customise. --- src/ComponentBroker.js | 32 ++++++++------- src/controllers/atoms/LogoutButton.js | 9 +++++ src/controllers/atoms/MessageTimestamp.js | 3 ++ src/controllers/molecules/MEmoteTile.js | 3 ++ src/controllers/molecules/MTextTile.js | 3 ++ src/controllers/molecules/MatrixToolbar.js | 3 ++ .../molecules/MessageComposer.js | 18 ++------- src/controllers/molecules/MessageTile.js | 3 ++ src/controllers/molecules/ProgressBar.js | 6 +++ src/controllers/molecules/RoomHeader.js | 3 ++ src/controllers/molecules/RoomTile.js | 10 +++++ src/controllers/molecules/SenderProfile.js | 3 ++ .../molecules/ServerConfig.js | 23 ++--------- .../molecules/UnknownMessageTile.js | 2 + src/{ => controllers}/organisms/RoomList.js | 21 +++------- src/{ => controllers}/organisms/RoomView.js | 34 ++-------------- src/{ => controllers}/pages/MatrixChat.js | 39 ++---------------- src/{ => controllers}/templates/Login.js | 38 +++--------------- src/index.js | 2 +- src/{ => views}/atoms/LogoutButton.js | 8 +--- src/{ => views}/atoms/MessageTimestamp.js | 4 ++ src/{ => views}/molecules/MEmoteTile.js | 4 ++ src/{ => views}/molecules/MTextTile.js | 4 ++ src/{ => views}/molecules/MatrixToolbar.js | 6 ++- src/views/molecules/MessageComposer.js | 16 ++++++++ src/{ => views}/molecules/MessageTile.js | 6 ++- src/{ => views}/molecules/ProgressBar.js | 7 ++-- src/{ => views}/molecules/RoomHeader.js | 4 ++ src/{ => views}/molecules/RoomTile.js | 10 +---- src/{ => views}/molecules/SenderProfile.js | 4 ++ src/views/molecules/ServerConfig.js | 24 +++++++++++ .../molecules/UnknownMessageTile.js | 4 ++ src/views/organisms/RoomList.js | 19 +++++++++ src/views/organisms/RoomView.js | 35 ++++++++++++++++ src/views/pages/MatrixChat.js | 40 +++++++++++++++++++ src/views/templates/Login.js | 37 +++++++++++++++++ 36 files changed, 303 insertions(+), 184 deletions(-) create mode 100644 src/controllers/atoms/LogoutButton.js create mode 100644 src/controllers/atoms/MessageTimestamp.js create mode 100644 src/controllers/molecules/MEmoteTile.js create mode 100644 src/controllers/molecules/MTextTile.js create mode 100644 src/controllers/molecules/MatrixToolbar.js rename src/{ => controllers}/molecules/MessageComposer.js (75%) create mode 100644 src/controllers/molecules/MessageTile.js create mode 100644 src/controllers/molecules/ProgressBar.js create mode 100644 src/controllers/molecules/RoomHeader.js create mode 100644 src/controllers/molecules/RoomTile.js create mode 100644 src/controllers/molecules/SenderProfile.js rename src/{ => controllers}/molecules/ServerConfig.js (62%) create mode 100644 src/controllers/molecules/UnknownMessageTile.js rename src/{ => controllers}/organisms/RoomList.js (80%) rename src/{ => controllers}/organisms/RoomView.js (60%) rename src/{ => controllers}/pages/MatrixChat.js (61%) rename src/{ => controllers}/templates/Login.js (78%) rename src/{ => views}/atoms/LogoutButton.js (62%) rename src/{ => views}/atoms/MessageTimestamp.js (69%) rename src/{ => views}/molecules/MEmoteTile.js (77%) rename src/{ => views}/molecules/MTextTile.js (71%) rename src/{ => views}/molecules/MatrixToolbar.js (61%) create mode 100644 src/views/molecules/MessageComposer.js rename src/{ => views}/molecules/MessageTile.js (87%) rename src/{ => views}/molecules/ProgressBar.js (82%) rename src/{ => views}/molecules/RoomHeader.js (66%) rename src/{ => views}/molecules/RoomTile.js (73%) rename src/{ => views}/molecules/SenderProfile.js (81%) create mode 100644 src/views/molecules/ServerConfig.js rename src/{ => views}/molecules/UnknownMessageTile.js (61%) create mode 100644 src/views/organisms/RoomList.js create mode 100644 src/views/organisms/RoomView.js create mode 100644 src/views/pages/MatrixChat.js create mode 100644 src/views/templates/Login.js diff --git a/src/ComponentBroker.js b/src/ComponentBroker.js index f3670bf65c..1d524267ec 100644 --- a/src/ComponentBroker.js +++ b/src/ComponentBroker.js @@ -1,7 +1,7 @@ var components = {}; function load(name) { - var module = require("./"+name); + var module = require("./views/"+name); components[name] = module; return module; }; @@ -23,17 +23,19 @@ module.exports = { // 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('./templates/Login'); +require('./views/atoms/LogoutButton'); +require('./views/atoms/MessageTimestamp'); +require('./views/molecules/MatrixToolbar'); +require('./views/molecules/RoomTile'); +require('./views/molecules/MessageTile'); +require('./views/molecules/SenderProfile'); +require('./views/molecules/UnknownMessageTile'); +require('./views/molecules/MTextTile'); +require('./views/molecules/MEmoteTile'); +require('./views/molecules/RoomHeader'); +require('./views/molecules/MessageComposer'); +require('./views/molecules/ProgressBar'); +require('./views/molecules/ServerConfig'); +require('./views/organisms/RoomList'); +require('./views/organisms/RoomView'); +require('./views/templates/Login'); diff --git a/src/controllers/atoms/LogoutButton.js b/src/controllers/atoms/LogoutButton.js new file mode 100644 index 0000000000..cac1776aad --- /dev/null +++ b/src/controllers/atoms/LogoutButton.js @@ -0,0 +1,9 @@ +var dis = require("../../dispatcher"); + +module.exports = { + onClick: function() { + dis.dispatch({ + action: 'logout' + }); + }, +}; diff --git a/src/controllers/atoms/MessageTimestamp.js b/src/controllers/atoms/MessageTimestamp.js new file mode 100644 index 0000000000..dd4f002d46 --- /dev/null +++ b/src/controllers/atoms/MessageTimestamp.js @@ -0,0 +1,3 @@ +module.exports = { +}; + diff --git a/src/controllers/molecules/MEmoteTile.js b/src/controllers/molecules/MEmoteTile.js new file mode 100644 index 0000000000..dd4f002d46 --- /dev/null +++ b/src/controllers/molecules/MEmoteTile.js @@ -0,0 +1,3 @@ +module.exports = { +}; + diff --git a/src/controllers/molecules/MTextTile.js b/src/controllers/molecules/MTextTile.js new file mode 100644 index 0000000000..dd4f002d46 --- /dev/null +++ b/src/controllers/molecules/MTextTile.js @@ -0,0 +1,3 @@ +module.exports = { +}; + diff --git a/src/controllers/molecules/MatrixToolbar.js b/src/controllers/molecules/MatrixToolbar.js new file mode 100644 index 0000000000..dd4f002d46 --- /dev/null +++ b/src/controllers/molecules/MatrixToolbar.js @@ -0,0 +1,3 @@ +module.exports = { +}; + diff --git a/src/molecules/MessageComposer.js b/src/controllers/molecules/MessageComposer.js similarity index 75% rename from src/molecules/MessageComposer.js rename to src/controllers/molecules/MessageComposer.js index 56fcdb18f8..61c4f30914 100644 --- a/src/molecules/MessageComposer.js +++ b/src/controllers/molecules/MessageComposer.js @@ -1,10 +1,8 @@ -var React = require('react'); +var MatrixClientPeg = require("../../MatrixClientPeg"); -var MatrixClientPeg = require("../MatrixClientPeg"); +var dis = require("../../dispatcher"); -var dis = require("../dispatcher"); - -module.exports = React.createClass({ +module.exports = { componentDidMount: function() { this.dispatcherRef = dis.register(this.onAction); }, @@ -43,13 +41,5 @@ module.exports = React.createClass({ ev.preventDefault(); } }, - - render: function() { - return ( -
-