Sha256: 5de80f5d9544cf05fc812404c4404c36f0ec076e022780b718065b98088a1954

Contents?: true

Size: 1.24 KB

Versions: 34

Compression:

Stored size: 1.24 KB

Contents

'use strict';

var inherits = require('inherits')
  , EventTarget = require('./eventtarget')
  ;

function EventEmitter() {
  EventTarget.call(this);
}

inherits(EventEmitter, EventTarget);

EventEmitter.prototype.removeAllListeners = function(type) {
  if (type) {
    delete this._listeners[type];
  } else {
    this._listeners = {};
  }
};

EventEmitter.prototype.once = function(type, listener) {
  var self = this
    , fired = false;

  function g() {
    self.removeListener(type, g);

    if (!fired) {
      fired = true;
      listener.apply(this, arguments);
    }
  }

  this.on(type, g);
};

EventEmitter.prototype.emit = function() {
  var type = arguments[0];
  var listeners = this._listeners[type];
  if (!listeners) {
    return;
  }
  // equivalent of Array.prototype.slice.call(arguments, 1);
  var l = arguments.length;
  var args = new Array(l - 1);
  for (var ai = 1; ai < l; ai++) {
    args[ai - 1] = arguments[ai];
  }
  for (var i = 0; i < listeners.length; i++) {
    listeners[i].apply(this, args);
  }
};

EventEmitter.prototype.on = EventEmitter.prototype.addListener = EventTarget.prototype.addEventListener;
EventEmitter.prototype.removeListener = EventTarget.prototype.removeEventListener;

module.exports.EventEmitter = EventEmitter;

Version data entries

34 entries across 33 versions & 12 rubygems

Version Path
ilog-0.4.0 node_modules/sockjs-client/lib/event/emitter.js
ilog-0.3.3 node_modules/sockjs-client/lib/event/emitter.js
jester-data-8.0.0 node_modules/sockjs-client/lib/event/emitter.js
ezii-os-5.2.1 node_modules/sockjs-client/lib/event/emitter.js
ezii-os-2.0.1 node_modules/sockjs-client/lib/event/emitter.js
ezii-os-1.1.0 node_modules/sockjs-client/lib/event/emitter.js
ezii-os-1.0.0 node_modules/sockjs-client/lib/event/emitter.js
ezii-os-0.0.0.1.0 node_modules/sockjs-client/lib/event/emitter.js
ezii-os-0.0.0.0.1 node_modules/sockjs-client/lib/event/emitter.js
optimacms-0.4.3 spec/dummy/node_modules/sockjs-client/lib/event/emitter.js
optimacms-0.4.2 spec/dummy/node_modules/sockjs-client/lib/event/emitter.js
cortex-0.1.3 spec/dummy/node_modules/sockjs-client/lib/event/emitter.js
dragonfly_puppeteer-0.1.0 node_modules/sockjs-client/lib/event/emitter.js
lanes-0.8.0 node_modules/sockjs-client/lib/event/emitter.js