boa-core
v0.8.0
Published
The core library for b-o-a
Downloads
14
Readme
boa-core
The core library for b-o-a.
Concepts
- uni-directional
- single dispatcher
- action cycle
Types
type O<T> = Observable<T>;
type A<T> = { type: string; data?: T; };
type HandlerOptions = { re: (action: A<any>) => void; };
type Handler = (action$: O<A<any>>, options?: HandlerOptions) => O<A<any>>;
type run = (app: Handler) => void
;
Installation
$ npm install boa-core [email protected] # you can use [email protected]
Usage
import { A, Handler, HandlerOptions, O, run } from 'boa-core';
import 'rxjs/add/observable/merge';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/scan';
const app: Handler = (
action$: O<A<any>>,
{ re }: HandlerOptions
): O<A<any>> => {
return O.merge(
O
.of({ count: 1 })
.merge(
action$
.filter(action => action.type === 'increment')
.map(() => state => state.count + 1)),
action$
.filter(action => action.type === 'decrement')
.map(() => state => state.count - 1))
)
.scan((state, updater) => updater(state))
.map(data => ({ type: 'render', data })),
// ...
);
};
run(app);