Skip to content

Commit

Permalink
Merge pull request facebook#172 from jarsbe/refactor/dispatcher
Browse files Browse the repository at this point in the history
Refactor/dispatcher
  • Loading branch information
fisherwebdev committed Mar 7, 2015
2 parents d48a06d + 4da3dca commit 172a114
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/flux-chat/js/actions/ChatMessageActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/flux-chat/js/actions/ChatServerActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion examples/flux-chat/js/actions/ChatThreadActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var ActionTypes = ChatConstants.ActionTypes;
module.exports = {

clickThread: function(threadID) {
ChatAppDispatcher.handleViewAction({
ChatAppDispatcher.dispatch({
type: ActionTypes.CLICK_THREAD,
threadID: threadID
});
Expand Down
5 changes: 0 additions & 5 deletions examples/flux-chat/js/constants/ChatConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

};
34 changes: 1 addition & 33 deletions examples/flux-chat/js/dispatcher/ChatAppDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
3 changes: 1 addition & 2 deletions examples/flux-chat/js/stores/MessageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
3 changes: 1 addition & 2 deletions examples/flux-chat/js/stores/ThreadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
3 changes: 1 addition & 2 deletions examples/flux-chat/js/stores/UnreadThreadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 172a114

Please sign in to comment.