Example:
This example will create ...
const store = new Store()
store.register$1('val1', newVal => { console.log("*" + newVal) }).subscribe()
store.select$('val1').subscribe(val => { if (val) console.log(val) })
store.update('val1', "Hello,")
store.update('val1', "World!")
Subject for compressing the history. See commit() for more information regarding the effect of the function. Example:
store.commit$s.next()
Subject for rollbacking the history. See rollback() for more information regarding the effect of the function. Example:
store.rollback$s.next()
Subject for updating the content of a data stored Example:
store.updater$s.next({ name: 'val1', data: 3})
Display the content of the store
Remove any data in the store (not the subscription)
Register an new value in the store Any select$ to the same name made before the registration will be hooked to this value. It is forbiden to register two values with the same name.
The namee of the value
Callback that will be called whenever the value changes because of the store (rollback...). The callback parameter is the new value.
An observable that is true when the value is subscribed
Return to the previous state in the history Going back to a previous state will trigger the callback function provided during the registration register$1 of any impacted values.
subscribe to a registered value in the store
the name of the value to subscribe to
an observable on the value. (The observable will never terminate) The subscribtion will remains if the value is unregistered from the store:
const store = new Store()
store.select$('val1').subscribe(val => { if (val) console.log(val) })
store.register$1('val1', newVal => { console.log("*" + newVal) }).subscribe()
store.update('val1', "Hello,")
store.unregister('val1')
store.register$1('val1', newVal => { console.log("*" + newVal) }).subscribe()
store.update('val1', "World!")
The returned observable only trigger if the stored value changes.
Unregister a value from the store Unregister value will not trigger any select$ to be closed.
The namee of the value.
Update a registered value in the store
The value to update
The new data to set
Generated using TypeDoc
A store class.
The store can be used to contain the states of an app.
One can add/remove data inside the store using the [[register]]/unregister method.
It is possible to set the value of a data using the update method or using the updater$s subject.
It is possible to subscribe to a value using the select$ observable.
The content of the store can be displayed using the dump() method and emptied using reset().
The store as an history that support rollback and can be flushed usinng commit.