0.8.0 • Published 10 years ago
boa-core v0.8.0
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 rxjs@5.0.0-beta.6 # you can use rxjs@5.xUsage
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);