@f/store
v1.0.1
Published
An observable store.
Downloads
4
Readme
store
An observable store.
Installation
$ npm install @f/store
Usage
var createStore = require('@f/store')
var combineReducers = require('@f/combine-reducers')
var store = createStore(combineReducers({foo: foo, bar: bar}))
store.dispatch({type: 'foo'})
store.getState() // => {foo: 1, bar: 0}
function foo (state, action) {
state = state || 0
return action.type === 'foo' ? 1 : state
}
function bar (state, action) {
state = state || 0
return action.type === 'bar' ? 2 : state
}
API
store(reducer, state)
reducer
- store reducerstate
- initial state of store
Returns: a store
.getState()
Returns: current state of the store
.dispatch(action)
action
- action to dispatch
subscribe(listener)
listener
- listener to call on store updates - signaturelistener(state)
replaceReducer(reducer)
reducer
- the reducer to use in place of the current reducer
License
MIT