@f/store

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @f/store

Weekly Downloads

4

Version

1.0.1

License

MIT

Last publish

Collaborators

  • f