How to use component-emitter - 10 common examples

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 rockstat / web-sdk / src / trackers / BrowserEventsTracker.js View on Github external
this.emit(INTERNAL_EVENT, DOM_BEFORE_UNLOAD);
    removeHandler(win, 'beforeunload', this.beforeUnloadHandler);

  };

  // Обработчик unload
  this.unloadHandler = () => {

    this.emit(INTERNAL_EVENT, DOM_UNLOAD);
    removeHandler(win, 'unload', this.unloadHandler);

  };
};

Emitter(BrowserEventsTracker.prototype);

BrowserEventsTracker.prototype.initialize = function () {

  addHandler(win, 'load', this.loadedHandler);
  addHandler(win, 'beforeunload', this.beforeUnloadHandler);
  addHandler(win, 'unload', this.unloadHandler);
};

export default BrowserEventsTracker;
github gardener / dashboard / frontend / src / utils / Emitter.js View on Github external
}

const url = window.location.origin
const socketConfig = {
  path: '/api/events',
  transports: ['websocket'],
  autoConnect: false
}

const shootsSocketAuthenticator = new SocketAuthenticator(io(`${url}/shoots`, socketConfig))
const journalsSocketAuthenticator = new SocketAuthenticator(io(`${url}/journals`, socketConfig))

const shootsEmitter = Emitter(new ShootsSubscription(shootsSocketAuthenticator))
const shootEmitter = Emitter(new ShootSubscription(shootsSocketAuthenticator))
const journalIssuesEmitter = Emitter(new IssuesSubscription(journalsSocketAuthenticator))
const journalCommentsEmitter = Emitter(new CommentsSubscription(journalsSocketAuthenticator))

const socketAuthenticators = [shootsSocketAuthenticator, journalsSocketAuthenticator]

/* Web Socket Connection */

forEach(socketAuthenticators, emitter => {
  emitter.socket.on('connect', attempt => emitter.onConnect(attempt))
  emitter.socket.on('reconnect', attempt => emitter.onConnect(attempt))
  emitter.socket.on('authenticated', () => emitter.onAuthenticated())
  emitter.socket.on('disconnect', reason => emitter.onDisconnect(reason))
  emitter.socket.on('connect_error', err => {
    console.error(`socket connection error ${err}`)
  })
  emitter.socket.on('connect_timeout', () => {
    console.error(`socket ${emitter.socket.id} connection timeout`)
  })
github gardener / dashboard / frontend / src / utils / Emitter.js View on Github external
return false
  }
}

const url = window.location.origin
const socketConfig = {
  path: '/api/events',
  transports: ['websocket'],
  autoConnect: false
}

const shootsSocketAuthenticator = new SocketAuthenticator(io(`${url}/shoots`, socketConfig))
const journalsSocketAuthenticator = new SocketAuthenticator(io(`${url}/journals`, socketConfig))

const shootsEmitter = Emitter(new ShootsSubscription(shootsSocketAuthenticator))
const shootEmitter = Emitter(new ShootSubscription(shootsSocketAuthenticator))
const journalIssuesEmitter = Emitter(new IssuesSubscription(journalsSocketAuthenticator))
const journalCommentsEmitter = Emitter(new CommentsSubscription(journalsSocketAuthenticator))

const socketAuthenticators = [shootsSocketAuthenticator, journalsSocketAuthenticator]

/* Web Socket Connection */

forEach(socketAuthenticators, emitter => {
  emitter.socket.on('connect', attempt => emitter.onConnect(attempt))
  emitter.socket.on('reconnect', attempt => emitter.onConnect(attempt))
  emitter.socket.on('authenticated', () => emitter.onAuthenticated())
  emitter.socket.on('disconnect', reason => emitter.onDisconnect(reason))
  emitter.socket.on('connect_error', err => {
    console.error(`socket connection error ${err}`)
  })
  emitter.socket.on('connect_timeout', () => {
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 rockstat / web-sdk / src / Transport.js View on Github external
this.pathPrefix = options.pathPrefix;
  this.server = this.options.server;
  this.wsServer = this.options.wsServer || this.options.server;
  this.wsPath = this.options.wsPath || '/wss';
  this.urlMark = this.options.urlMark;
  this.wsConnected = false;
  this.servicesMap = {
    'track': 't4k'
  }
  this.msgCounter = new Date() - 1514764800000;
  this.waitCallers = {};
};


// Extending Emitter
Emitter(Transport.prototype);


/**
 * Set default credentials that used to send data to server
 * @param {Object} creds object containing creds
 * @returns {Transport}
 */
Transport.prototype.setCreds = function (creds) {
  this.creds = objectAssign({}, creds);
  return this;
}


/**
 * Transform path to query url
 * @param {string} path
github weapp-socketio / wxapp-socket-io / src / engine.js View on Github external
import Emitter from 'component-emitter'
import on from './on'
import parsejson from './parsejson'
import bind from 'component-bind'
import parseuri from 'parseuri'

export default Engine

const GlobalEmitter = Emitter({ hasEmitte: false })

Emitter(Engine.prototype)

const packets = {
  open:     0,    // non-ws
  close:    1,    // non-ws
  ping:     2,
  pong:     3,
  message:  4,
  upgrade:  5,
  noop:     6,
}

const packetslist = Object.keys(packets)

function Engine(uri, opts) {
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.
 */

component-emitter

Simple event emitter

MIT
Latest version published 3 months ago

Package Health Score

85 / 100
Full package analysis