A tiny module for managing state.
npm install send-action
var createStore = require('send-action')
var state = {
items: []
}
var actions = {
setItem: function (state, data) {
state.items.push(data)
return state
}
}
function onChange (state, action) {
// render app
console.log(state, action)
}
var send = createStore({
state: state,
actions: actions,
onChange: onChange
})
send('setItem', { title: 'hi' })
- choo
- The early versions of choo used send-action! Now choo uses an event emitter approach for managing state which is very cool yet slightly more verbose than I prefer.
- unistore - The latest version of send-action looks a little more like unistore than it did before. Some differences of send-action include:
- the source is not transpiled before publish and sticks to es5
- state is mutable, so there's no
setState
function - managing action functions is a little simpler
- not returning state from an action avoids triggering the
onChange
handler - no way to subscribe listeners, only the
onChange
handler - if you use react, you'll have an easier time using unistore as it comes with a
Provider
component
Contributions are welcome! Please read the contributing guidelines first.
Help keep this project open and inclusive. Please read and follow the code of conduct
Read about the changes to this project in CHANGELOG.md. The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- issues – Please open issues in the issues queue