send-action
v4.0.2
Published
simple state management
Downloads
44
Maintainers
Readme
send-action
A tiny module for managing state.
Install
npm install send-action
Minimal example
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' })
See also
- 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
Contributing
Contributions are welcome! Please read the contributing guidelines first.
Conduct
Help keep this project open and inclusive. Please read and follow the code of conduct
Changelog
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.
Contact
- issues – Please open issues in the issues queue