1.2.2 • Published 8 years ago

set-state-mixin v1.2.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

set-state-mixin

npm.io Dependency Status npm.io npm.io 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

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago