downspout

0.0.4 • Public • Published

downspout

npm version CircleCI

README: ( English | 日本語 )

A framework to serialize the execution of event handlers for disorderly event emitting

Functions of this module

  • Provide a framework for describing event handlers.
  • Allow one event handler to execute as transaction processing.
  • Queue the execution of event handlers.

Installation

npm install --save downspout

Please use browserify (or webpack) when using with browser.

Usage

Overview

const Downspout = require('downspout');
 
const state = {
  counter: 0,
};
 
const useCases = {
  increment: () => {
    return Promise.resolve({
      type: 'INCREMENT',
    });
  },
  decrement: () => {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve({
          type: 'DECREMENT',
        });
      }, 1000);
    });
  },
};
 
const downspout = new Downspout(useCases);
 
downspout.on('execution:resolved', ({ result: action }) => {
  switch (action.type) {
    case 'INCREMENT':
      state.counter += 1;
      break;
    case 'DECREMENT':
      state.counter -= 1;
      break;
  }
 
  process.stdout.write(`${ state.counter }\n`);
});
 
downspout.execute('increment');  // -> "1"
downspout.execute('increment');  // -> "2"
downspout.execute('decrement');  // -> "1"
downspout.execute('increment');  // -> "2"
downspout.execute('decrement');  // -> "1"

Basic usage by CLI counter samples

with the React

(Later)

with the Redux

As far as using bindActionCreators, it was impossible.

Readme

Keywords

Package Sidebar

Install

npm i downspout

Weekly Downloads

1

Version

0.0.4

License

MIT

Last publish

Collaborators

  • kjirou