基于facebook官方flux模型,进行了一些整理和加工,隐藏了dispatcher,简化了flux的操作流程;
create your action:
var Action = Flux.createAction( function(resolve){
return {
do_soming: function(){
return webutils.xxx.done(function(data){
resolve(data);
});
},
...
};
});
create your store:
var Store = Flux.createStore( function(){
return {
do_soming: function(data){
//processing..
return data;
},
...
};
});
in your component:
var Test = React.createClass({
...
componentDidMount: function(){
this.storeListeners = Store.listen({
'do_soming': this.onDone
});
},
componentWillUnmount: function(){
Store.listenOff(this.storeListeners);
},
onDone: function(data){
//now is your choice
}
...
})
打开控制台,或许能帮到你!
Basic example: TodoMVC