jasondippel / leaguespot

FYDP
0 stars 1 forks source link

Flux Store Design #10

Closed jasondippel closed 7 years ago

jasondippel commented 8 years ago

How to Design and Use a Store

Flux stores will be setup for the logged in user, fantasy leagues, players (professional) and teams. They will be used to store all the information for these items as it is retrieved from the database.

Updating a Store

A store will be updated after a certain time interval (tbd). This updating will trigger a re-rendering of all listening components. They may also be updated on a call to a given action/method.

What to Include in Components

For components that use a store, they will need to listen to change events that it triggers. In order to do this, components must include the following in the component's class:

componentWillMount() {
  Store.on("change", this.setSomeStateVal.bind(this));
}

componentWillUnmount() {
  Store.removeListener("change", this.setSomeStateVal.bind(this));
}

If you wish to run some function as soon as the component loads and need to pass in a ref value, use the following code:

componentDidMount() {
  if(!this.state.StateItem) {
    Actions.someAction(this.props.params.param);
  }
}

This code should only be used to initiate the loading of data into a store and not the retrieval of it.

jasondippel commented 7 years ago

Outdated. Using Redux now.