leaf-store
v0.0.1
Published
State manager.
Downloads
2
Readme
leaf-store
state manager
Install
Feature
- 支持并兼容已有的 redux 中间件
- 支持 combineReducers
Usage
Write a initialState:
const initialState = {
counter: 0,
}
Write a reducer:
const reducer = (state = initialState, action) => {
switch(action.type) {
case('ADD_COUNTER'): {
return Object.assign({}, state, {
counter: state.counter + 1
})
}
default: {
return state
}
}
}
Then create store:
const store = createStore(reducer, applyMiddleware(thunkMiddleware))
Use store.getState to get store state:
store.getState()
Use store.dispatch to dispatch action:
store.dispatch({
type: 'ADD_COUNTER'
})
API
Similar to Redux.
createStore(reducer, applyMiddleware) Create store from reducer and applyMiddleware(optional). Return store.
combineReducers(reducerA, reducerB, ...) Return a root reducer from seperated reduce module. Usage like createStore(combineReducers(reducerA, reducerB, ...)).
applyMiddleware(middlewareA, middlewareB, ...) Usage like createStore(reducer, applyMiddleware(middlewareA, middlewareB, ...)). Then you will get store, with middleware integration.
LICENSE
MIT