A simple state management handler
npm i @fiad/toolbox
import Store from '@fiad/toolbox/store'
const store = new Store({ ...initialState })
It retrieves the whole current state or the current value of the given property.
const state = store.get()
// or if only one property is needed
const someProp = store.get('someProp')
It updates the values of the given properties, while the rest of the state remains preserved.
store.set({ someProp: 'newValue', otherProp: 'otherValue' })
// or if only one property needs to be updated
store.set('someProp', 'newValue')
It resets the state to its initial value.
store.reset()
It adds a listener that runs the given callback when the given property is updated.
const callback = value => console.log(value)
store.observe('someProp', callback)
// the updated value of someProp will be logged in the console on change
It removes the listener registered for the given property.
store.unobserve('someProp', callback)