1.0.1 • Published 8 years ago

@f/store v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

store

Build status Git tag NPM version Code style

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 reducer
  • state - 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 - signature listener(state)

replaceReducer(reducer)

  • reducer - the reducer to use in place of the current reducer

License

MIT