@stamp/eventemittable

1.0.2 • Public • Published

@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.
  • domains are not supported.

Readme

Keywords

none

Package Sidebar

Install

npm i @stamp/eventemittable

Weekly Downloads

37

Version

1.0.2

License

MIT

Unpacked Size

6.54 kB

Total Files

4

Last publish

Collaborators

  • stamp