rx-store
rx-store
is a reactive solution for managing state. It is framework and view agnostic, though it can be used as the basis for a Flux pattern.
Installation
npm install --save rx-store
Usage
Import library
ES6
;
ES5 with modules
var createRxStore = createRxStore;
ES5
// window.RxStore.createRxStore
Create a store
createRxStore
takes a reduce function as an argument as well as an optional initial state. If not specified the initial state starts out as undefined. Note that the state can be any valid JS type (object, array, number, etc.).
{ return previousState + nextState;}var initialState = 0;var store = ;
Subscribe to State Changes
store; // which is equivalent to storestate$;
Modify State
var action = 4;store; store;// State: 0// State: 4
Modify State from Browser Event
var addTwo$ = RxObservable; // send each new action to the storeaddTwo$;
Using as a Flux Pattern
{ }var initialState = count: 0 somethingElse: 'data';var store = ; { return type: 'ADD' payload: data ;} var addAction = ;var addAction2 = ;store;store; store;// {count: 0, somethingElse: 'data'}// {count: 4, somethingElse: 'data');// {count: 3, somethingElse: 'data');
Using with React Views
Component { thiscountSubscription = thispropscountStream; } { thiscountSubscription; } { return <div>thisstatecount</div>; } var count$ = storestate$;ReactDOM;