Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjirou/downspout
A framework to serialize the execution of event handlers for disorderly event emitting
https://github.com/kjirou/downspout
event-handlers javascript nodejs
Last synced: 12 days ago
JSON representation
A framework to serialize the execution of event handlers for disorderly event emitting
- Host: GitHub
- URL: https://github.com/kjirou/downspout
- Owner: kjirou
- License: mit
- Created: 2016-11-16T16:30:53.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T07:58:55.000Z (about 3 years ago)
- Last Synced: 2024-08-09T07:29:24.522Z (3 months ago)
- Topics: event-handlers, javascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 461 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# downspout
[![npm version](https://badge.fury.io/js/downspout.svg)](https://badge.fury.io/js/downspout)
[![CircleCI](https://circleci.com/gh/kjirou/downspout.svg?style=svg)](https://circleci.com/gh/kjirou/downspout)README: ( [English](/README.md) | [日本語](/README_.ja.md) )
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
```bash
npm install --save downspout
```Please use [browserify](https://github.com/substack/node-browserify)
(or [webpack](https://github.com/webpack/webpack)) when using with browser.## Usage
### Overview
![](/doc/overview.png)```js
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
- [The simplest example](/examples/counter-1.js)
- Keywords:
- Use-cases
- constructor
- "execution:resolved" event
- execute
- [Wait for completion of asynchronous processing](/examples/counter-2.js)
- Keywords:
- Promise
- [Pass arguments to use-cases](/examples/counter-3.js)
- Keywords:
- Use-case arguments
- [Specify the variables on which the use case depends](/examples/counter-4.js)
- Keywords:
- context
- [Implementation pattern like the Flux](/examples/counter-5.js)
- Keywords:
- result
- [Runtime error handling](/examples/counter-6.js)
- Keywords:
- "execution:rejected" event
- error
- [Runtime error handling for development](/examples/counter-7.js)
- Keywords:
- isNoisy
- [Constants](/examples/counter-8.js)
- Keywords:
- EVENT_NAMES.USE_CASE_EXECUTION_RESOLVED
- EVENT_NAMES.USE_CASE_EXECUTION_REJECTED
- [Fork other use-cases](/examples/counter-9.js)
- Keywords:
- utils.fork
- [Separate layers of use cases and UI events](/examples/counter-10.js)
- Keywords:
- routes
- dispatch
- [Generate bound event emitters to pass any view libraries](/examples/counter-11.js)
- Keywords:
- generateExecutor
- generateDispatcher
- [Conclusion: Operable counter](/examples/counter-conclusion-1.js)
- Example of the Flux (like) format
- [Conclusion: Fizz Buzz Game](/examples/counter-conclusion-2.js)
- Example of the MVC format### with the React
(Later)