Skip to content

Instantly share code, notes, and snippets.

@flarnie
Created December 9, 2014 00:47
Show Gist options
  • Save flarnie/11a5e83fa7fe23a307e1 to your computer and use it in GitHub Desktop.
Save flarnie/11a5e83fa7fe23a307e1 to your computer and use it in GitHub Desktop.
Flux TodoApp Sample 7
// 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