boa-core
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

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.x

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);

Badges

Circle CI

License

MIT

Author

bouzuya <m@bouzuya.net> (http://bouzuya.net)

Readme

Keywords

Package Sidebar

Install

npm i boa-core

Weekly Downloads

2

Version

0.8.0

License

MIT

Last publish

Collaborators

  • bouzuya