rauricoste-store-sync
v0.0.6
Published
Summary ===
Downloads
7
Readme
Summary
It provides a store with an immutable state and easy methods to update the state, and listening to input and output changes.
Exemple
const Store = require("rauricoste-store-sync")
const store = new Store({value: 1})
store.getState()
// returns {value: 1}
const commands = store.getCommandEmitter()
commands.set("value", 2)
store.getState()
// returns {value: 2}
commands.set("object.sub.subSub", 3)
store.getState()
// returns {
value: 2,
object: {
sub: {
subSub: 3
}
}
}
API
getState()
: returns the current statesetState(state: Any)
: sets the current state tostate
value.subscribe(function)
: listens to state changes. Every time the state changes,function
is called with an object as follows :
{
newState: {}, // new state
oldState: {}, // previous state
command: {} // the command that triggered the change in the state
}
getCommandEmitter()
: returns an instance with the same methods as Immutable. When this instance methods are called, a command is created and sent to the store that then changes its internal state.inStream
: instance of EventStream that publishes commands sent to the storeoutStream
: instance of EventStream that publishes state changes. Seesubscribe
method.