How to use the events.EventEmitter.prototype function in events

To help you get started, we’ve selected a few events 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 kevinbarabash / debugger / src / task.js View on Github external
* Currently used by tests only to simulate non-stepper tasks.
 * In the future this class will be used to separate task concerns
 * from the Stepper.
 */

// TODO: browserify EventEmitter for use in tests
var EventEmitter = require("events").EventEmitter;

// TODO: move this to /test
function Task(action) {
    EventEmitter.call(this);
    this._started = false;
    this.action = action;
}

Task.prototype = Object.create(EventEmitter.prototype);
Task.prototype.constructor = Task;

Task.prototype.start = function () {
    this._started = true;
    this.action();
};

Task.prototype.complete = function () {
    this.emit("done");
};

Task.prototype.started = function () {
    return this._started;
};

module.exports = Task;
github gugui3z24 / MEAN-Stack-With-Angular-2-Tutorial / node_modules / mongoose / lib / model.js View on Github external
// apply methods and statics
  applyMethods(d, schema);
  applyStatics(d, schema);

  return d;
};

// Model (class) features

/*!
 * Give the constructor the ability to emit events.
 */

for (var i in EventEmitter.prototype) {
  Model[i] = EventEmitter.prototype[i];
}

/**
 * Called when the model compiles.
 *
 * @api private
 */

Model.init = function init() {
  if ((this.schema.options.autoIndex) ||
      (this.schema.options.autoIndex == null && this.db.config.autoIndex)) {
    this.ensureIndexes({ __noPromise: true, _automatic: true });
  }

  this.schema.emit('init', this);
};
github summernote / winternote / js / stores / NoteStore.js View on Github external
var NoteDispatcher = require('../dispatcher/NoteDispatcher'),
    NoteConstants = require('../constants/NoteConstants'),
    EventEmitter = require('events').EventEmitter,
    _ = require('lodash'),
    Editor = require('../models/Editor'),
    mockData = require('../mockData');

var NoteStore = _.extend({
  editor: new Editor(mockData)
}, EventEmitter.prototype, {
  emitChange: function (type) {
    this.emit(type);
  },

  addChangeListener: function (callback, type) {
    this.on(type, callback);
  },

  removeChangeListener: function (callback, type) {
    this.removeListener(type, callback);
  },

  getEditor: function () {
    return this.editor;
  }
});
github fossasia / susi.ai / src / stores / SettingStore.js View on Github external
import ChatAppDispatcher from '../dispatcher/ChatAppDispatcher';
import ChatConstants from '../constants/ChatConstants';
import { EventEmitter } from 'events';

let ActionTypes = ChatConstants.ActionTypes;
let CHANGE_EVENT = 'change';

let _searchMode = false;

let SettingStore = {
    ...EventEmitter.prototype,

    emitChange() {
        this.emit(CHANGE_EVENT);
    },

    getSearchMode() {
        return _searchMode;
    },

    addChangeListener(callback) {
        this.on(CHANGE_EVENT, callback);
    },

    removeChangeListener(callback) {
        this.removeListener(CHANGE_EVENT, callback);
    },
github pattern-lab / patternlab-node / packages / cli / bin / utils.js View on Github external
this.emit(
        'patternlab.debug',
        `${chalk.green('⊙ patternlab →')} ${chalk.dim(msg)}`
      );
    },
    info(msg) {
      this.emit('patternlab.info', `⊙ patternlab → ${chalk.dim(msg)}`);
    },
    error(msg) {
      this.emit(
        'patternlab.error',
        `${chalk.red('⊙ patternlab →')} ${chalk.dim(msg)}`
      );
    },
  },
  EventEmitter.prototype
);

/**
 * @func debug
 * @desc Coloured debug log
 * @param  {*} msg - The variadic messages to log out.
 * @return {void}
 */
const debug = log.debug.bind(log);

/**
 * @func info
 * @desc Coloured debug log
 * @param  {*} msg - The variadic messages to log out.
 * @return {void}
 */
github ManInTheBox / nodejs.rs / node_modules / mongoose / lib / document.js View on Github external
this.isNew = true;

  if (obj) this.set(obj, undefined, true);

  this._registerHooks();
  this.doQueue();

  this.errors = undefined;
  this._shardval = undefined;
};

/**
 * Inherit from EventEmitter.
 */

Document.prototype.__proto__ = EventEmitter.prototype;

/**
 * Base Mongoose instance for the model. Set by the Mongoose instance upon
 * pre-compilation.
 *
 * @api public
 */

Document.prototype.base;

/**
 * Document schema as a nested structure.
 *
 * @api public
 */
github muchmala / socket.io-cluster / lib / app-node.js View on Github external
SocketIoAdapter.prototype._removeClient = function(client) {
    if (client.sessionId in this.clients) {
        delete this.clients[client.sessionId];
    }
};


function Client(info, server) {
    for (var keys = Object.keys(info), i = keys.length; i--; ) {
        this[keys[i]] = info[keys[i]];
    }

    this.listener = server;
}

Client.prototype.__proto__ = EventEmitter.prototype;

Client.prototype.send = function(data) {
    this.listener.broadcastOnly(data, this.sessionId);
};

Client.prototype.broadcast = function(data) {
    this.listener.broadcast(data, this.sessionId);
};

Client.prototype.broadcastToChannel = function(channel, data) {
    this.listener.broadcastToChannel(channel, data, this.sessionId);
};

Client.prototype.subscribeToChannel = function(channelId) {
    var message = this.listener.server.createMessage({
        channel: channelId
github itead / IoTgo / protocol / index.js View on Github external
* { 'sequenceValue': { req: reqObj, callback: callbackFunc, timer: setTimeout() } }
 */
var pendingRequests = {};
var removePendingRequest = function (sequence) {
  var pending = pendingRequests[sequence];
  if (! pending) return;

  pending.callback(interceptors(pending.req, { error: 504, reason: 'Request Timeout' }));
  delete pendingRequests[sequence];
};

/**
 * Exports
 */
module.exports = exports;
mixin(exports, EventEmitter.prototype);

exports.postRequest = function (req, callback) {
  if (! validate(req)) {
    callback(interceptors(req, { error: 400, reason: 'Bad Request' }));
    return;
  }

  if (typeof methods[req.action] !== 'function') {
    callback(interceptors(req, {
      error: 400,
      reason: 'Bad Request'
    }));
    return;
  }

  if (req.action !== 'update' ||  utils.fromDevice(req) ||