An emitter-like way to distributively create and modify objects.
$ npm install jumpin --save
const Jumpin = require('jumpin');
const emitter = new Jumpin();
const allPredicate = () => true;
const timePredicate = (data) => {
return typeof data.time === 'number';
};
emitter.on(allPredicate, (obj) => {
obj.time = Date.now();
//returning true means that failed predicates will be reexamine
//note: listeners that were invoked in this cycle won't get invoke again
//returning false or undefined means that failed predicates might not get reexamined
return true;
});
//async operation - will delay main pipeline
emitter.on(timePredicate, (obj) => {
return new Promise((resolve) => {
setTimeout(() => {
obj.time = new Date(obj.time).toISOString();
return resolve(false);
}, 250);
});
});
emitter.trigger({
type: 'first-event'
})
.then((data) => {
console.log(data.type); //log 'first-event'
console.log(data.time); //log formatted date
});
Full API documentation is yet to be written, but you can view the source and examples.
- fix usage as node module
- update package.json
- update documentation
- update documentation
- update documentation
- minor changes
- fix bug in rerun mechanism
- use PromiseCtor instead of promiseFactory
- first release (beta)