re-atom
v0.1.2
Published
Another Clojure-style atom library for javascript
Downloads
5
Maintainers
Readme
A library providing simple Clojure atom-inspired state management (for React)
Installation
npm install --save re-atom
General API
atom(module) => atom
atom(middleware, module) => atom
atom(middleware) => (module) => atom
type Module = { initialState: mixed, actions: { [string]: (AtomInterface, ...args: Array) => void }, actionGenerators: { [string]: ActionGenerator }, modules: { [string]: Module }, }
type ActionGenerator = AtomInterface => ActionType
Middleware functions have the following signature: (next) => (initialState, resetFn, actionFn) => void
.
The resetFn signature is: (oldState, newState) => void
.
The actionFn signature is: (scope, actionHandler, params, actionPath) => void
.
deref(atom)
swap(atom, xf, ...args)
xf = (oldState, ...args) => newState
reset(atom, newState)
dispatch(atom, action, ...args)
addWatch(atom, watcherFn)
watcherFn = (atom, newState, oldState) => void
removeWatch(atom, watcherFn)
wrapGenerator(genFn, ...args)
React API
<Provider stateAtom={atom}>
connect(mapStateFn, mapActionsFn)
mapStateFn = (state, ownProps) => props
mapActionsFn = (atom, ownProps) => actionProps