@stamp/eventemittable
v1.0.2
Published
Node.js' EventEmitter as a stamp
Downloads
51
Readme
@stamp/eventemittable
Node.js' EventEmitter as a stamp
const EventEmittable = require('@stamp/eventemittable');
// or
import EventEmittable from '@stamp/eventemittable';
Example
Create event emitter object:
const emitter = EventEmittable();
Create a Stamp which implements Node.js' EventEmitter
API via composition:
import stampit from '@stamp/it';
const MyStamp = stampit({
methods: {
foo () {
this.emit('foo', 'bar');
}
}
})
.compose(EventEmittable);
const myObject = MyStamp();
myObject.on('foo', value => {
console.log(`value: ${value}`);
});
myObject.foo(); // prints "value: bar"
Notes
- For portability, this package consumes the userland
EventEmitter
implementation of the events package. domain
s are not supported.