Honeycombs
State manager with built-in side-effects.
Install
npm i -S honeycombs
or yarn add honeycombs
API
;
hc.of(initialState): Honeycomb
— creates instance ofHoneycomb
.
Honeycomb
Honeycomb
is store. Store can to create handlers (Bee
instances) by this methods:
-
honeycomb.transform(payload => oldState => newState): Bee
-
honeycomb.apply(payload => newState): Bee
-
honeycomb.apply(payload => oldState => newState): Bee
-
honeycomb.just(): Bee
—Bee
just sets state to received payload value. -
honeycomb.always(constantValue): Bee
—Bee
always sets state toconstantValue
. -
honeycomb.fromPromise(payload => Promise<newState>): Bee
honeycomb.fromPromise(payload => Promise<oldState => newState>): Bee
Order of state changes depends on order of promises resolving.
-
honeycomb.awaitPromise(payload => Promise<newState>): Bee
honeycomb.awaitPromise(payload => Promise<oldState => newState>): Bee
Order of state changes depends on order of
Bee
in call queue. Resolving of this promise blocks to the queue. -
honeycomb.fromObservable(payload => Observable<newState>): Bee
honeycomb.fromObservable(payload => Observable<oldState => newState>): Bee
All values of
Observable
will change the state. Order of state changes depends on order ofObservable
values. -
honeycomb.awaitObservable(payload => Observable<newState>): Bee
honeycomb.awaitObservable(payload => Observable<oldState => newState>): Bee
All values of
Observable
will change the state. Awaiting ofObservable
complete blocks to the queue.
Honeycomb
is Observable
. You can to subscribe to store using method subscribe
:
honeycomb.subscribe(next [, error, complete] ): Subscription
honeycomb.subscribe(observer): Subscription
Observer
is object with optional methods:
observer.next(newState)
observer.error(Error)
observer.complete()
Subscription
is object with method unsubscribe()
.
Bee
Bee
is store handler. This is:
- Function that can receive a payload value.
- Observer that have method
next()
, receives a payload value. Observable
of state values, emits only when thisBee
was called. So you can to subscribe to state changes, executed of specifiedBee
.
Usage
; const counter = hc; const reset = counter;const setTo = counter;const increment = counter;const decrement = counter;const add = counter;const subtract = counter; ; // 1; // 2; // 1; // 6; // 5; // 10; // 0
With observable streams
;; const user = hc; const login = user; const refresh = user; const logout = user; ; ;;;
With promises
; const posts = hc; const loadPosts = posts; ;;