Created
December 9, 2014 00:47
-
-
Save flarnie/11a5e83fa7fe23a307e1 to your computer and use it in GitHub Desktop.
Flux TodoApp Sample 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TodoStore emits a 'change' event after handling the action. | |
// ... | |
// Register to handle all updates | |
AppDispatcher.register(function(payload) { | |
var action = payload.action; | |
var text; | |
switch(action.actionType) { | |
case TodoConstants.TODO_CREATE: | |
text = action.text.trim(); | |
if (text !== '') { | |
create(text); | |
} | |
break; | |
// ... | |
default: | |
return true; | |
} | |
// This often goes in each case that should trigger a UI change. This store | |
// needs to trigger a UI change after every view action, so we can make the | |
// code less repetitive by putting it here. We need the default case, | |
// however, to make sure this only gets called after one of the cases above. | |
TodoStore.emitChange(); | |
return true; // No errors. Needed by promise in Dispatcher. | |
}); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment