0.0.6 • Published 7 years ago

rauricoste-store-sync v0.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

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 state
  • setState(state: Any) : sets the current state to state 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 store
  • outStream : instance of EventStream that publishes state changes. See subscribe method.
0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago