@ainc/onion
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@ainc/onion

Let's do something nice with @ainc/onion!

Install

$ yarn add @ainc/onion

Usage

import { Onion } from '@ainc/onion';

// create onion
const onion = new Onion();

// add `increase` action.
onion.add('increase', ctx => {
    ctx.count ++;
    ctx.next();
});

// add `decrease` action.
onion.add('decrease', ctx => {
    ctx.count --;
    ctx.next();
});

// add common action.
onion.add(ctx => {
    ctx.count >= 3 && ctx.next();
});

// call untyped action, this will output '3'.
onion.call({ count: 3 }, (res) => console.log(res.count));

// call 'increase' action, this will output '4'.
onion.call('increase', { count: 3 }, (res) => console.log(res.count));

// call 'decrease' action, this will no output.
onion.call('decrease', { count: 3 }, (res) => console.log(res.count));

API

  • add(type: string, handler: Handler<T>): () => void;
  • add(handler: Handler<T>): () => void;
  • call(type: string, state?: T, callback?: Callback<T>): void | Promise<void>;
  • call(action?: Action<T>, callback?: Callback<T>): void | Promise<void>;
  • clear(): void;

Readme

Keywords

none

Package Sidebar

Install

npm i @ainc/onion

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

19.9 kB

Total Files

10

Last publish

Collaborators

  • absock
  • edonet