React Reflux Stores:使用参数调用trigger()与不使用参数之间的区别

时间:2015-11-23 02:20:11

标签: reactjs store state flux refluxjs

我有一个带有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();
  }

1 个答案:

答案 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());
    }
  }