@anic/onion

onion

Usage no npm install needed!

<script type="module">
  import anicOnion from 'https://cdn.skypack.dev/@anic/onion';
</script>

README

@anic/onion

Onion for JavaScript

Install

$ yarn add @anic/onion

Usage

import onion from '@anic/onion';

// create
const { add, tap } = onion();

// add Function action
add((type, value) => ({ type, value }));

// add Object action
add({
    value: 1,
    add(num: number): any {
        return this.next(this.value += num;);
    }
});

// tap action
tap('add', 1);

Api

onion(context: Object): { add: Function, tap: Function }

create onion Object, which contain add and tap function;

add(action: Object | Function): () => void

add action, return remove handler;

tap(name: string, ...args: any[]): any

tap action by name and args;