0.0.1 • Published 6 years ago

@wesleytodd/state-container v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 years ago

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
*/