set-state-mixin

1.2.2 • Public • Published

set-state-mixin

Dependency Status Code Climate

setState like behavior for Reflux stores.

Install

npm install --save set-state-mixin

Usage

var reflux = require('reflux')
var setStateMixin = require('set-state-mixin')

var INITIAL_STATE = {
  loading: false,
  people: [],
}

var PeopleStore = Reflux.createStore({
  mixins: {
    setStateMixin(INITIAL_STATE)
  },

  onCreate: function (person) {
    this.setState({
      loading: true,
    })

    request.post('/people', person)
      .then(function (newPerson) {
        // Add the new person to the list of people.
        this.state.people.push(newPerson)

        // Indicate loading is finished and trigger an
        // update of the store with the new person.
        this.setState({
          loading: false,
          people: this.state.people,
        })
      }.bind(this))
      .catch(function (err) {
        // Do some sort of error handling...
        this.setState({
          loading: false,
        })
      }.bind(this))
  }
})

API

See the API docs for full documentation.

License

MIT © Dana Woodman

Package Sidebar

Install

npm i set-state-mixin

Weekly Downloads

0

Version

1.2.2

License

MIT

Last publish

Collaborators

  • danawoodman