Ling Zhong
Ling Zhong

Reputation: 1804

React Reflux Stores: Difference between calling trigger() with parameters vs. without parameters

I have a React App with a Reflux Store where some components listen to the trigger() and then calls the Reflux store getters to retrieve its updated states. i.e.

var Store = Reflux.createStore({
  init: function() {
    this.filterList = [];
    ... // listening to actions
  }

  onNewFilterItemAction: function(item) {
    this.filterList.push(item);
    this.trigger(...);
  }
});

What's the difference between calling trigger() with parameters vs without? Namely:

  onNewFilterItemAction: function(item) {
    this.filterList.push(item);
    this.trigger(this.filterList);
  }

vs.

  onNewFilterItemAction: function(item) {
    this.filterList.push(item);
    this.trigger();
  }

Upvotes: 2

Views: 1448

Answers (1)

J. Mark Stevens
J. Mark Stevens

Reputation: 4945

You can selectively update.

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

Upvotes: 1

Related Questions