I started with FLUX very recently, and need some advise on how should I update the component state and the store.
I need to set a toggle flag which is bonded to an onclick event, from what I understand in Flux architecture, I should call an action then trigger a dispatch event and then the store will update and emit update resulting my component to receive the update and re-render. (Please correct me if I'm wrong here) Component Code look like this:
...
_updateState:function(){
this.setState({myTrigger: MyStore.myTrigger});
},
_onClickEvent: function(boolValue){
MyActions.updateTrigger(boolValue);
},
...
render: function(){
return: (
...<div onClick={this._onClickEvent}/>...
)
}
...
I wonder why shouldn't I just call setState directly which would trigger the re-render directly and avoid going through the full flux cycle which I don't really need since I will always pass in "true" for this function, which really is the same as not passing any data over to the store. Code will look like this:
...
_onClickEvent: function(){
this.setState({myTrigger: true});
}
...
Seemly to me this is by-passing the flux single directly process flow concept and creating a component event loop within the component. Is this wrong to do? Can anyone help me understand the reasoning behind why this is a good or bad practice to do so?
Thank you very much! DD