Skip to content
ListenTo helper mixin for any object conforming to EventEmitter interface.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests
.gitignore
.jshintrc
.npmignore
LICENSE
README.md
index.js
package.json

README.md

listen-emitter

Mixin for event-emitter inversion of control listen functions

Useage

var extend = require('extend');
var Emitter = require('events').EventEmitter;
var ListenToEmitter = require('listento-emitter');

// creates class using emitter and listento functions
function AirportEntity() { }
extend(AirportEntity.prototype, Emitter, ListenToEmitter);

// create instances (have listenTo/ListenOnce/stopListening)
var tower = new AirportEntity();
var plane = new AirportEntity();

// tower listens for place.emit calls
tower.listenTo(plane, 'ready-to-land', function () {
  log('the plane is ready to land');
})

// causes tower's listenTo callback to fire
plane.emit('ready-to-land');

Methods

Methods are defined with the expectation that they will be extended into an instance or prototype of an object. They won't work as static functions.

listenTo(obj, events, callback)

Creates a listener that fires callback function when target object events are emitted.

tower.listenTo(plane, 'ready-to-takeoff', function () { })

listenOnce(obj, events, callback)

Creates a listener that fires callback function once when target object events are emitted.

plane.listenOnce(tower, 'thumbs-up', function () { })

stopListening(obj, events, callback)

Removes specified listener. If any of the arguments are undefined, listeners that match remaining arguments will be removed. If no arguments are passed, all listeners will be removed.

tower.stopListening(plane);
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.