A framework to serialize the execution of event handlers for disorderly event emitting
- Provide a framework for describing event handlers.
- Allow one event handler to execute as transaction processing.
- Queue the execution of event handlers.
npm install --save downspout
Please use browserify (or webpack) when using with browser.
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"
- The simplest example
- Keywords:
- Use-cases
- constructor
- "execution:resolved" event
- execute
- Keywords:
- Wait for completion of asynchronous processing
- Keywords:
- Promise
- Keywords:
- Pass arguments to use-cases
- Keywords:
- Use-case arguments
- Keywords:
- Specify the variables on which the use case depends
- Keywords:
- context
- Keywords:
- Implementation pattern like the Flux
- Keywords:
- result
- Keywords:
- Runtime error handling
- Keywords:
- "execution:rejected" event
- error
- Keywords:
- Runtime error handling for development
- Keywords:
- isNoisy
- Keywords:
- Constants
- Keywords:
- EVENT_NAMES.USE_CASE_EXECUTION_RESOLVED
- EVENT_NAMES.USE_CASE_EXECUTION_REJECTED
- Keywords:
- Fork other use-cases
- Keywords:
- utils.fork
- Keywords:
- Separate layers of use cases and UI events
- Keywords:
- routes
- dispatch
- Keywords:
- Generate bound event emitters to pass any view libraries
- Keywords:
- generateExecutor
- generateDispatcher
- Keywords:
- Conclusion: Operable counter
- Example of the Flux (like) format
- Conclusion: Fizz Buzz Game
- Example of the MVC format
(Later)