Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

1.1.0

Latest

Choose a tag to compare

@aleclarson aleclarson released this 04 Jun 16:48
· 11 commits to master since this release

🐳 Bring your own event emitter

The se.reader function now accepts an event emitter (or just a plain object that maps event names to listeners) as its second argument. The event emitter can be any object with an emit method.

// provide listeners directly
se.reader(socket, {
  '*': console.log,
});

// use node's EventEmitter
const EventEmitter = require('events');
const events = new EventEmitter();
se.reader(socket, events);

// use the socket as the event emitter
se.reader(socket, socket);

// use any object with an emit method
se.reader(socket, {
  emit(name, $1, $2) {
    console.log(name, $1, $2);
  }
});

The se.reader function now returns its associated event emitter, instead of a listen function.

const events = new EventEmitter();
events === se.reader(socket, events); // true

// plain objects without an `emit` method are wrapped with `se.events`
const events = { foo: console.log };
events !== se.reader(socket, events); // true
  • The default EventEmitter class has been reworked to conform to a compatible interface.
  • se.events has been added, which takes an (optional) plain object that maps event names to listener functions or arrays. It returns a new instance of the default EventEmitter class.