leaf-store
State manager.
Last updated 2 years ago by jin5354 .
MIT · Original npm · Tarball · package.json
$ cnpm install leaf-store 
SYNC missed versions from official npm registry.

leaf-store

Build Status Coverage Status

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

Current Tags

  • 0.0.1                                ...           latest (2 years ago)

1 Versions

  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (12)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |