From 1beef2f8a216d85cc1c25ac39182ab01aee022d3 Mon Sep 17 00:00:00 2001 From: jarsbe Date: Sat, 7 Mar 2015 10:22:29 +0700 Subject: [PATCH 1/4] Removed unneeded constants. --- examples/flux-chat/js/constants/ChatConstants.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/flux-chat/js/constants/ChatConstants.js b/examples/flux-chat/js/constants/ChatConstants.js index 9ad48408c80781..4a462610f29fc3 100644 --- a/examples/flux-chat/js/constants/ChatConstants.js +++ b/examples/flux-chat/js/constants/ChatConstants.js @@ -19,11 +19,6 @@ module.exports = { CREATE_MESSAGE: null, RECEIVE_RAW_CREATED_MESSAGE: null, RECEIVE_RAW_MESSAGES: null - }), - - PayloadSources: keyMirror({ - SERVER_ACTION: null, - VIEW_ACTION: null }) }; From 9068c1ab4eb744c47c4b8b00116aae4fc385a845 Mon Sep 17 00:00:00 2001 From: jarsbe Date: Sat, 7 Mar 2015 10:22:51 +0700 Subject: [PATCH 2/4] Reduce dispatcher to non-modified instance. --- .../js/dispatcher/ChatAppDispatcher.js | 34 +------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/examples/flux-chat/js/dispatcher/ChatAppDispatcher.js b/examples/flux-chat/js/dispatcher/ChatAppDispatcher.js index 0e7e9885c9b093..e2c637d3af7417 100644 --- a/examples/flux-chat/js/dispatcher/ChatAppDispatcher.js +++ b/examples/flux-chat/js/dispatcher/ChatAppDispatcher.js @@ -10,38 +10,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var ChatConstants = require('../constants/ChatConstants'); var Dispatcher = require('flux').Dispatcher; -var assign = require('object-assign'); -var PayloadSources = ChatConstants.PayloadSources; - -var ChatAppDispatcher = assign(new Dispatcher(), { - - /** - * @param {object} action The details of the action, including the action's - * type and additional data coming from the server. - */ - handleServerAction: function(action) { - var payload = { - source: PayloadSources.SERVER_ACTION, - action: action - }; - this.dispatch(payload); - }, - - /** - * @param {object} action The details of the action, including the action's - * type and additional data coming from the view. - */ - handleViewAction: function(action) { - var payload = { - source: PayloadSources.VIEW_ACTION, - action: action - }; - this.dispatch(payload); - } - -}); - -module.exports = ChatAppDispatcher; +module.exports = new Dispatcher(); From 104848c6c98abff9c0dc1a854394de7ab0033731 Mon Sep 17 00:00:00 2001 From: jarsbe Date: Sat, 7 Mar 2015 10:28:53 +0700 Subject: [PATCH 3/4] Make actions use new dispatcher API. --- examples/flux-chat/js/actions/ChatMessageActionCreators.js | 2 +- examples/flux-chat/js/actions/ChatServerActionCreators.js | 4 ++-- examples/flux-chat/js/actions/ChatThreadActionCreators.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/flux-chat/js/actions/ChatMessageActionCreators.js b/examples/flux-chat/js/actions/ChatMessageActionCreators.js index ac66cdd818eee6..03c328024137b1 100644 --- a/examples/flux-chat/js/actions/ChatMessageActionCreators.js +++ b/examples/flux-chat/js/actions/ChatMessageActionCreators.js @@ -20,7 +20,7 @@ var ActionTypes = ChatConstants.ActionTypes; module.exports = { createMessage: function(text, currentThreadID) { - ChatAppDispatcher.handleViewAction({ + ChatAppDispatcher.dispatch({ type: ActionTypes.CREATE_MESSAGE, text: text, currentThreadID: currentThreadID diff --git a/examples/flux-chat/js/actions/ChatServerActionCreators.js b/examples/flux-chat/js/actions/ChatServerActionCreators.js index 9aa92f408646d2..3ae69e49e0e29c 100644 --- a/examples/flux-chat/js/actions/ChatServerActionCreators.js +++ b/examples/flux-chat/js/actions/ChatServerActionCreators.js @@ -18,14 +18,14 @@ var ActionTypes = ChatConstants.ActionTypes; module.exports = { receiveAll: function(rawMessages) { - ChatAppDispatcher.handleServerAction({ + ChatAppDispatcher.dispatch({ type: ActionTypes.RECEIVE_RAW_MESSAGES, rawMessages: rawMessages }); }, receiveCreatedMessage: function(createdMessage) { - ChatAppDispatcher.handleServerAction({ + ChatAppDispatcher.dispatch({ type: ActionTypes.RECEIVE_RAW_CREATED_MESSAGE, rawMessage: createdMessage }); diff --git a/examples/flux-chat/js/actions/ChatThreadActionCreators.js b/examples/flux-chat/js/actions/ChatThreadActionCreators.js index fa63c9cd68b8aa..f362a3790bf726 100644 --- a/examples/flux-chat/js/actions/ChatThreadActionCreators.js +++ b/examples/flux-chat/js/actions/ChatThreadActionCreators.js @@ -18,7 +18,7 @@ var ActionTypes = ChatConstants.ActionTypes; module.exports = { clickThread: function(threadID) { - ChatAppDispatcher.handleViewAction({ + ChatAppDispatcher.dispatch({ type: ActionTypes.CLICK_THREAD, threadID: threadID }); From 4da3dca2a3e837c844ba632cbcec149d674b7e64 Mon Sep 17 00:00:00 2001 From: jarsbe Date: Sat, 7 Mar 2015 10:29:27 +0700 Subject: [PATCH 4/4] Change store callback to accept action. --- examples/flux-chat/js/stores/MessageStore.js | 3 +-- examples/flux-chat/js/stores/ThreadStore.js | 3 +-- examples/flux-chat/js/stores/UnreadThreadStore.js | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/flux-chat/js/stores/MessageStore.js b/examples/flux-chat/js/stores/MessageStore.js index a461c9b2227eaf..995ef3997934e1 100644 --- a/examples/flux-chat/js/stores/MessageStore.js +++ b/examples/flux-chat/js/stores/MessageStore.js @@ -93,8 +93,7 @@ var MessageStore = assign({}, EventEmitter.prototype, { }); -MessageStore.dispatchToken = ChatAppDispatcher.register(function(payload) { - var action = payload.action; +MessageStore.dispatchToken = ChatAppDispatcher.register(function(action) { switch(action.type) { diff --git a/examples/flux-chat/js/stores/ThreadStore.js b/examples/flux-chat/js/stores/ThreadStore.js index 4ccd000a82bf89..a73ceb39b5cb54 100644 --- a/examples/flux-chat/js/stores/ThreadStore.js +++ b/examples/flux-chat/js/stores/ThreadStore.js @@ -102,8 +102,7 @@ var ThreadStore = assign({}, EventEmitter.prototype, { }); -ThreadStore.dispatchToken = ChatAppDispatcher.register(function(payload) { - var action = payload.action; +ThreadStore.dispatchToken = ChatAppDispatcher.register(function(action) { switch(action.type) { diff --git a/examples/flux-chat/js/stores/UnreadThreadStore.js b/examples/flux-chat/js/stores/UnreadThreadStore.js index 9e2ab9bf944299..a95eeaf82e9d7e 100644 --- a/examples/flux-chat/js/stores/UnreadThreadStore.js +++ b/examples/flux-chat/js/stores/UnreadThreadStore.js @@ -53,13 +53,12 @@ var UnreadThreadStore = assign({}, EventEmitter.prototype, { }); -UnreadThreadStore.dispatchToken = ChatAppDispatcher.register(function(payload) { +UnreadThreadStore.dispatchToken = ChatAppDispatcher.register(function(action) { ChatAppDispatcher.waitFor([ ThreadStore.dispatchToken, MessageStore.dispatchToken ]); - var action = payload.action; switch (action.type) { case ActionTypes.CLICK_THREAD: