@wesleytodd/state-container

0.0.1 • Public • Published

State Container

NPM Version NPM Downloads Build Status js-happiness-style

A state container for any javascript app. Unopinionated and minimalistic.

Usage

npm i --save @wesleytodd/state-container
const createStore = require('@wesleytodd/state-container')

const store = createStore(function reducer (state = 0, action) {
  return state + action.value
}, 1)

store.subscribe((state) => {
  console.log(state)
})

store.dispatch({
  value: 1
})

store.dispatch(Promise.resolve({
  value: 2
}))

store.dispatch((dispatch) => {
  dispatch({
    value: 3
  })
  dispatch({
    value: 4
  })
})

console.log(`Final State: ${store.getState()}`)

/*
2
4
7
11
Final State: 11
*/

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i @wesleytodd/state-container

    Weekly Downloads

    1

    Version

    0.0.1

    License

    ISC

    Unpacked Size

    5.67 kB

    Total Files

    5

    Last publish

    Collaborators

    • wesleytodd