0.0.4 • Published 7 years ago

downspout v0.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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

npm.io

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.

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago