How to use the component-emitter.prototype function in component-emitter

To help you get started, we’ve selected a few component-emitter 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 tableflip / guvnor / web / client / helpers / socket.js View on Github external
var Emitter = require('component-emitter')
var config = require('clientconfig')

if (config.debugMode) {
  // only extend if we're in debug mode
  Emitter.prototype.emit = function (event) {
    this._callbacks = this._callbacks || {}

    var argsWithoutEvent = Array.prototype.slice.call(arguments, 1)
    var argsWithEvent = Array.prototype.slice.call(arguments, 0)

    for (var eventName in this._callbacks) {
      if (!Array.isArray(this._callbacks[eventName])) {
        continue
      }

      var callbacks = this._callbacks[eventName].slice()
      var hasWildCard = eventName.indexOf('*') !== -1
      var subEvent = eventName.split('*')[0]

      if (eventName === event) {
        for (var i = 0; i < callbacks.length; i++) {
github SocketCluster / sc-crud-sample / public / socketcluster.js View on Github external
},{"dup":6}],14:[function(require,module,exports){
var Emitter = require('component-emitter');

if (!Object.create) {
  Object.create = require('./objectcreate');
}

var SCEmitter = function () {
  Emitter.call(this);
};

SCEmitter.prototype = Object.create(Emitter.prototype);

SCEmitter.prototype.emit = function (event) {
  if (event == 'error' && this.domain) {
    // Emit the error on the domain if it has one.
    // See https://github.com/joyent/node/blob/ef4344311e19a4f73c031508252b21712b22fe8a/lib/events.js#L78-85
    
    var err = arguments[1];
    
    if (!err) {
      err = new Error('Uncaught, unspecified "error" event.');
    }
    err.domainEmitter = this;
    err.domain = this.domain;
    err.domainThrown = false;
    this.domain.emit('error', err);
  }
github ranjithprabhuk / ng2-Dashboard / node_modules / socket.io-client / lib / socket.js View on Github external
disconnect: 1,
  error: 1,
  reconnect: 1,
  reconnect_attempt: 1,
  reconnect_failed: 1,
  reconnect_error: 1,
  reconnecting: 1,
  ping: 1,
  pong: 1
};

/**
 * Shortcut to `Emitter#emit`.
 */

var emit = Emitter.prototype.emit;

/**
 * `Socket` constructor.
 *
 * @api public
 */

function Socket(io, nsp){
  this.io = io;
  this.nsp = nsp;
  this.json = this; // compat
  this.ids = 0;
  this.acks = {};
  this.receiveBuffer = [];
  this.sendBuffer = [];
  this.connected = false;
github GeReV / mpdisco / client / js / vendor / socket.io-client / lib / socket.js View on Github external
connect_error: 1,
  connect_timeout: 1,
  disconnect: 1,
  error: 1,
  reconnect: 1,
  reconnect_attempt: 1,
  reconnect_failed: 1,
  reconnect_error: 1,
  reconnecting: 1
};

/**
 * Shortcut to `Emitter#emit`.
 */

var emit = Emitter.prototype.emit;

/**
 * `Socket` constructor.
 *
 * @api public
 */

function Socket(io, nsp){
  this.io = io;
  this.nsp = nsp;
  this.json = this; // compat
  this.ids = 0;
  this.acks = {};
  if (this.io.autoConnect) this.open();
  this.receiveBuffer = [];
  this.sendBuffer = [];
github alekseykulikov / storage-emitter / src / index.js View on Github external
/* eslint-env browser */
import Emitter from 'component-emitter'
const emit = Emitter.prototype.emit

/**
 * Use communication `KEY` to ignore other localStorage changes.
 */

const KEY = '!!storage-emitter-key'

/**
 * Use `TEST_KEY` to detect private browsing mode
 */

const TEST_KEY = '!!storage-emitter-key-test'

/**
 * Initialize an `Emitter` instance.
 */
github android-js / androidjs-builder / bin / dist / app-debug / assets / myapp / node_modules / socket.io-client / lib / socket.js View on Github external
disconnect: 1,
  error: 1,
  reconnect: 1,
  reconnect_attempt: 1,
  reconnect_failed: 1,
  reconnect_error: 1,
  reconnecting: 1,
  ping: 1,
  pong: 1
};

/**
 * Shortcut to `Emitter#emit`.
 */

var emit = Emitter.prototype.emit;

/**
 * `Socket` constructor.
 *
 * @api public
 */

function Socket (io, nsp, opts) {
  this.io = io;
  this.nsp = nsp;
  this.json = this; // compat
  this.ids = 0;
  this.acks = {};
  this.receiveBuffer = [];
  this.sendBuffer = [];
  this.connected = false;
github taataa / tapspace / lib / AbstractNode.js View on Github external
// Nodes with null parent are root nodes i.e. spaces.
  // AbstractNode#remove sets _parent to null.
  this._parent = null

  // Keep track on node siblings in two-way linked list manner.
  this._prevSibling = null
  this._nextSibling = null

  // Dict because good key search time complexity
  this._children = {}
  // List for children order
  this._order = []
}

var p = extend({}, Emitter.prototype)
AbstractNode.prototype = p

p.addChild = function (child, i) {
  // Add the given AbstractNode as a child and remove it from its old parent.
  child.setParent(this, i)

  return this
}

p.bringAbove = function (sibling) {
  // Remove this node from the old parent and add to a new parent so that
  // the given node becomes the next sibling of the node.
  //
  if (sibling.isRoot()) {
    throw new Error('Cannot send after a root node.')
  }
github SocketCluster / socketcluster-client / lib / sctransport.js View on Github external
// connecting, we want to close it manually with a 1006 - This is necessary
    // to prevent inconsistent behavior when running the client in Node.js
    // vs in a browser.

    if (self.state === self.CONNECTING) {
      self._onClose(1006);
    }
  };

  this._connectTimeoutRef = setTimeout(function () {
    self._onClose(4007);
    self.socket.close(4007);
  }, this.connectTimeout);
};

SCTransport.prototype = Object.create(Emitter.prototype);

SCTransport.CONNECTING = SCTransport.prototype.CONNECTING = 'connecting';
SCTransport.OPEN = SCTransport.prototype.OPEN = 'open';
SCTransport.CLOSED = SCTransport.prototype.CLOSED = 'closed';

SCTransport.prototype.uri = function () {
  var query = this.options.query || {};
  var schema = this.options.secure ? 'wss' : 'ws';

  if (this.options.timestampRequests) {
    query[this.options.timestampParam] = (new Date()).getTime();
  }

  query = querystring.encode(query);

  if (query.length) {
github ayamflow / image-progress / index.js View on Github external
this.options.autoclear = this.options.autoclear || true;
    this.options.leading = this.options.leading || 2;

    this.loaded = 0;
    this.total = 0;
    this.progress = 0;

    this.request = new XMLHttpRequest();
    this.request.onprogress = this.onProgress.bind(this);
    this.request.onload = this.onComplete.bind(this);
    this.request.onerror = this.onError.bind(this);

    if(this.options.autostart) this.load();
};

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

ImageProgress.prototype.load = function() {
    this.request.open('GET', this.options.url, true);
    this.request.overrideMimeType('text/plain; charset=x-user-defined');
    this.request.send(null);
    if(this.options.onStart) this.options.onStart(this.options);
    this.emit('start', this.options);
};

ImageProgress.prototype.onProgress = function(event) {
    if(!event.lengthComputable) return;

    this.loaded = event.loaded;
    this.total = event.total;
    this.progress = +(this.loaded / this.total).toFixed(this.options.leading);
github keen / keen-js / src / core / utils / emitter-shim.js View on Github external
var Emitter = require('component-emitter');
Emitter.prototype.trigger = Emitter.prototype.emit;
module.exports = Emitter;

component-emitter

Simple event emitter

MIT
Latest version published 5 months ago

Package Health Score

84 / 100
Full package analysis