我有一个带有Reflux
商店的React App,其中一些组件会监听trigger()
,然后调用Reflux
商店getters
来检索其更新状态。即。
var Store = Reflux.createStore({
init: function() {
this.filterList = [];
... // listening to actions
}
onNewFilterItemAction: function(item) {
this.filterList.push(item);
this.trigger(...);
}
});
使用参数vs没有调用trigger()
之间的区别是什么?即:
onNewFilterItemAction: function(item) {
this.filterList.push(item);
this.trigger(this.filterList);
}
VS
onNewFilterItemAction: function(item) {
this.filterList.push(item);
this.trigger();
}
答案 0 :(得分:1)
您可以有选择地更新。
componentDidMount = () => { this.unsubscribe = BasicStore.listen(this.storeDidChange); }
componentWillUnmount = () => { this.unsubscribe(); }
storeDidChange = (id) => {
switch (id) {
case 'data1': this.setState({Data1: BasicStore.getData1()}); break;
case 'data2': this.setState({Data2: BasicStore.getData2()}); break;
case 'data3': this.setState({Data3: BasicStore.getData3()}); break;
default: this.setState(getState());
}
}