How to use the component-emitter 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 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 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 anthonyshort / deku / test / dom / index.js View on Github external
test('rendering new elements should be batched with state changes', ({equal,end}) => {
  var app = deku()
  var el = div()
  var renderer = render(app, el)
  var mount = app.mount.bind(app)
  var unmount = app.unmount.bind(app)
  var emitter = new Emitter()
  var i = 0

  var ComponentA = {
    initialState: function(){
      return {
        text: 'Deku Shield'
      }
    },
    afterMount: function(component, el, updateState) {
      emitter.on('data', text => updateState({ text: text }))
    },
    render: function({props,state}){
      i++
      return <div>{props.text} {state.text}</div>
    }
  }
github conveyal / transitive.js / lib / core / network.js View on Github external
this.reLookup[key] = rEdge
    }
    return rEdge
  }

  addVertexPoint (point) {
    if (this.baseVertexPoints.indexOf(point) !== -1) return
    this.baseVertexPoints.push(point)
  }
}

/**
 * Mixin `Emitter`
 */

Emitter(Network.prototype)
github weapp-socketio / wxapp-socket-io / src / manager.js View on Github external
import Emitter from 'component-emitter'
import bind from 'component-bind'
import Backoff from 'backo2'
import indexOf from 'indexof'
import on from './on'
import Engine from './engine'
import { encoder, decoder } from './parser'
import Socket from './socket'

const has = Object.prototype.hasOwnProperty

Emitter(Manager.prototype)

export default Manager

function Manager(uri, opts) {
  if (!(this instanceof Manager)) return new Manager(uri, opts)

  opts.path = opts.path || 'socket.io'
  this.nsps = {}
  this.subs = []
  this.opts = opts
  this.uri = uri
  this.readyState = 'closed'
  this.connected = false
  this.reconnection(opts.reconnection !== false)
  this.reconnectionAttempts(opts.reconnectionAttempts || Infinity)
  this.reconnectionDelay(opts.reconnectionDelay || 1000)
github conveyal / transitive.js / lib / transitive.js View on Github external
this.display.applyTransform(transform)
    this.render()
  }

  /** editor functions **/

  createVertex (wx, wy) {
    this.network.graph.addVertex(new Point(), wx, wy)
  }
}

/**
 * Mixin `Emitter`
 */

Emitter(Transitive.prototype)
github weapp-socketio / wxapp-socket-io / src / socket.js View on Github external
import Emitter from 'component-emitter'
import on from './on.js'
import bind from 'component-bind'

Emitter(Socket.prototype)

const parser = {
  CONNECT:      0,
  DISCONNECT:   1,
  EVENT:        2,
  ACK:          3,
  ERROR:        4,
  BINARY_EVENT: 5,
  BINARY_ACK:   6,
}

const events = {
  connect: 1,
  connect_error: 1,
  connect_timeout: 1,
  connecting: 1,

component-emitter

Simple event emitter

MIT
Latest version published 6 months ago

Package Health Score

84 / 100
Full package analysis