@converge/state ·
Minimal state management library similar to redux
, with immer
built in.
installation
yarn add @converge/state
npm i @converge/state
usage
import { createStore } from "@converge/state"
const store = createStore({ count: 0 }, {
plus: (by = 1) => state => { state.count += by },
minus: (by = 1) => state => { state.count -= by },
reset: () => () => ({ count: 0 })
})
const { plus, minus, reset } = store.getActions()
const unsubscribe = store.subscribe(() => {
console.log(store.getState())
})
plus()
plus(2)
minus(2)
reset()
unsubscribe()
const { state, actions } = store.useStore()
console.log(state)
actions.plus(10)
console.log(state)
console.log(store.getState())
see also
redux
– predictable state container for JS appsimmer
– create the next immutable state by mutating the current one
contributing
Search the issues if you come
across any trouble, open a new one if it hasn't been posted, or, if you're
able, open a pull request.
Contributions of any kind are welcome in this project.
license
MIT © Bo Lingen / citycide