How to use eventemitter2 - 10 common examples

To help you get started, we’ve selected a few eventemitter2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dshaw / socket.io-redis / lib / redis-store.js View on Github external
data = undefined;
    } else {
      try {
        data = JSON.parse(data);
      } catch (e) { /* then data is what it is */ }
    }
    console.log('redis subscriber', event, data);
    self.emit(event, data);
  });
}

/**
 * Monkey patch Socket.IO Store to use EventEmitter2 instead of events.EventEmitter
 */

Store.prototype.__proto__ = EventEmitter2.prototype;

/**
 * Inherits from Socket.IO Store
 */

util.inherits(RedisStore, Store);


/**
 * Namespaced keys.
 *
 * @param {String} key
 *
 * @api private
 */
github dandean / tubbs / lib / model.js View on Github external
Object.defineProperty(this, '__cid__', {
    value: createId()
  });
  
  if (this.initialize) this.initialize();
  this.initialized = true;

  // Emit "new" event on next tick so that the instance exists within the Model
  // dataStore when handlers are notified.
  setTimeout(function() {
    this.constructor.emit('new', this);
  }.bind(this), 0)
}

// Extend EventEmitter2
Tubbs.prototype = Object.create(EventEmitter2.prototype);

Object.defineProperties(Tubbs.prototype, {
  // Define 'fields' object on Tubbs base. Model class's `fields' property will
  // use this as their __proto__ object.
  fields: {
    value: {}
  },

  /**
   * Tubbs#toJSON() -> Object
   * Returns an object representing the model which is ready for serialization.
  **/
  toJSON: {
    value: function() {
      var json = {};
github RobotWebTools / roslibjs / build / roslib.js View on Github external
});

  this.on('result', function(result) {
    that.isFinished = true;
    that.result = result;
  });

  this.on('feedback', function(feedback) {
    that.feedback = feedback;
  });

  // Add the goal
  this.actionClient.goals[this.goalID] = this;
}

Goal.prototype.__proto__ = EventEmitter2.prototype;

/**
 * Send the goal to the action server.
 *
 * @param timeout (optional) - a timeout length for the goal's result
 */
Goal.prototype.send = function(timeout) {
  var that = this;
  that.actionClient.goalTopic.publish(that.goalMessage);
  if (timeout) {
    setTimeout(function() {
      if (!that.isFinished) {
        that.emit('timeout');
      }
    }, timeout);
  }
github 20chix / Autonomus_Indoor_Drone / aid_webapp / src / ros_build / roslib.js View on Github external
});

  feedbackListener.subscribe(function(feedbackMessage) {
      that.emit('status', feedbackMessage.status);
      that.emit('feedback', feedbackMessage.feedback);
  });

  // subscribe to the result topic
  resultListener.subscribe(function(resultMessage) {
      that.emit('status', resultMessage.status);
      that.emit('result', resultMessage.result);
  });

}

ActionListener.prototype.__proto__ = EventEmitter2.prototype;

module.exports = ActionListener;

},{"../core/Message":12,"../core/Topic":19,"eventemitter2":2}],9:[function(require,module,exports){
/**
github noseglid / atom-build / spec / fixture / node_modules / grunt / lib / grunt / event.js View on Github external
/*
 * grunt
 * http://gruntjs.com/
 *
 * Copyright (c) 2014 "Cowboy" Ben Alman
 * Licensed under the MIT license.
 * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
 */

'use strict';

// External lib.
var EventEmitter2 = require('eventemitter2').EventEmitter2;

// Awesome.
module.exports = new EventEmitter2({wildcard: true});
github joecritch / container-queries / node_modules / grunt / lib / grunt / event.js View on Github external
/*
 * grunt
 * http://gruntjs.com/
 *
 * Copyright (c) 2013 "Cowboy" Ben Alman
 * Licensed under the MIT license.
 * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
 */

'use strict';

// External lib.
var EventEmitter2 = require('eventemitter2').EventEmitter2;

// Awesome.
module.exports = new EventEmitter2({wildcard: true});
github daviddias / webrtc-explorer / modules / chord.js View on Github external
function node(config) {
  localStorage.debug = config.logging || false;
  // t = canela.createTracer({emitter: ee, active: config.tracing || false});

  var id = uuid.gen();                  // our node id
  // var fingers = fingerTable.create(id); // create our nitty finger table
  var predecessor;
  var sucessor;                       
  var emitter = new eventEmitter2({ wildcard: true, newListener: false, maxListeners: 80 });

  /// Joining the Chord network through Signaling procedures

  var url = (config.signalingURL || 'http://default.url') + (config.namespace || '/');
  var ioClient = io(url);
  ioClient.on('connect', join);
  
  // warmup mode join
  ioClient.on('c-warmup-predecessor', acceptPredecessor);
  ioClient.on('c-warmup-sucessor', acceptSucessor);

  // normal mode join/rail new node
  ioClient.on('c-response', joinResponse);
  ioClient.on('c-predecessor', newPredecessor);
  ioClient.on('c-sucessor', newSucessor);
github tinkerhub / tinkerhub / lib / net / tcp.js View on Github external
constructor(transport) {
		this.transport = transport;
		this.events = new EventEmitter2();

		// Reply to hello messages with our metadata
		this.events.on('hello', msg => {
			this.id = msg.id;
			this.version = msg.version;

			this.write('metadata', {
				id: this.transport.id,
				version: 1
			});
		});
	}
github christianalfoni / flux-angular / release / flux-angular.js View on Github external
var Store = function (dispatcher) {
    this.dispatcher = dispatcher;

    // Check if store exists when waiting for it
    this.waitFor = function (stores, cb) {
      stores = Array.isArray(stores) ? stores : [stores];
      if (!flux.isStoresRegistered(stores)) {
        throw new Error('Waiting for stores that are not injected into Angular yet, ' + stores.join(', ') + '. Be sure to inject stores before waiting for them');
      }
      this.dispatcher.waitFor(stores, cb.bind(this));
    };

    // Call the constructor of EventEmitter2
    EventEmitter2.call(this, {
      wildcard: true
    });

    if (typeof maxListeners === 'number') {
      this.setMaxListeners(maxListeners);
    } else if (maxListeners && typeof maxListeners[name] === 'number') {
      this.setMaxListeners(maxListeners[name]);
    }

    if (this.initialize) {
      this.initialize();
    }
  };
github FGRibreau / node-children / lib / Children.js View on Github external
function Children(workerPath, options) {
  if (!(this instanceof Children)) {
    return new Children(workerPath, options);
  }

  EventEmitter2.call(this, {
    wildcard: false
  });

  this.options = _.defaults(options || {}, Children.defaults);
  this.options.workerPath = workerPath;

  if (!this.options.resetEnv) {
    this.options.spawn_options.env = process.env;
  }

  // Children array
  this.childs = [];
  this._shuttingDown = false;

  if (this.options.autoRestart) {
    this.on('killed:child', this._autorespawn.bind(this));

eventemitter2

A feature-rich Node.js event emitter implementation with namespaces, wildcards, TTL, async listeners and browser/worker support.

MIT
Latest version published 2 years ago

Package Health Score

82 / 100
Full package analysis