seal-store
A simple framework agnostic state store where the state
object is immutable by any means other than a setState
function.
const state setState = statesaxPlayingSeal = 'looking bad' // => throws TypeError console // looking good console // looking good but is getting dizzy
Properties of the state object must be defined in the initState
and cannot be removed.
const state setState = // => throws TypeError
This rule is true infinitely deep.
const state setState = // => throws TypeError
There is one exception to adding/removing properties: arrays can shrink or grow. However, in any objects inside of them (other than arrays) properties cannot be added/removed.
const state setState = // this is fine // this is also fine
seal-store
also comes with the ability to add a callback when any key in the state is updated.
const stateHasBeenUpdated = { console } const state setState = // => 'the state has been updated'
Unlike other state stores, seal-store
doesn't need spread syntax ({ ...items }
) for changes that apply to child objects
const state setState = console // => { secondLevel: { updated: true, stillHere: true } }
Install
yarn add seal-store
or
npm add --save seal-store
or as a script tag
proxy
Support
seal-store
uses proxy
objects. If you need to provide IE support, you'll need a proxy polyfill. You can look at the full compatibility table on MDN.
LICENSE
MIT © Ben Williams