set-state-mixin
v1.2.2
Published
Reflux `setState` mixin to get React-like state behavior in Reflux stores.
Downloads
12
Maintainers
Readme
set-state-mixin
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.