Created
April 24, 2017 14:32
-
-
Save mushfiqweb/26beb53e798731a33223d99895f1a62f to your computer and use it in GitHub Desktop.
This file contains 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
/* STANDARD FLUX */ | |
// Using flux you need to register the action in the dispatcher | |
AppDispatcher.register(function(payload) { | |
var action = payload.action; | |
var text; | |
switch(action.actionType) { | |
case 'updateTodo': | |
text = action.text.trim(); | |
if (text !== '') { | |
TodoStore.find( action.todo ).text = text; | |
TodoStore.emitChange(); | |
} | |
break; | |
} | |
}); | |
// and also build the action creator | |
var TodoActions = { | |
update: function( todo, text ) { | |
dispatcher.handleViewAction({ | |
actionType: 'updateTodo', | |
text: text, | |
todo: todo | |
}); | |
} | |
} | |
// Inside your component you need to imperatively | |
// call the action, coupling your component to the | |
// action object | |
var TodoList = React.createComponent({ | |
... | |
updateTodo: function( todo, text ){ | |
TodoActions.update( todo, text ); | |
} | |
... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment