set-state-mixin

Reflux `setState` mixin to get React-like state behavior in Reflux stores.

Usage no npm install needed!

<script type="module">
  import setStateMixin from 'https://cdn.skypack.dev/set-state-mixin';
</script>

README

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