How to use eventemitter3 - 10 common examples

To help you get started, we’ve selected a few eventemitter3 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 maxpert / raspchat / src / chat-user.js View on Github external
constructor(id, ws, nick, options) {
        this.events = new E3.EventEmitter();
        this.id = id;
        this.nick = nick;
        this.options = Object.assign({}, DefaultOptions, options);
        this.lastSeen = new Date().getTime();

        this._ws = ws;
        this._joined = new Map();

        debug('User connected with', this.id, this.nick, this.lastSeen);
        this._ws.on('message', message => {
            // Message from user
            this.events.emit(
                'message',
                this.options.parser.fromSerialized(message),
                this);
        });
github video-dev / hls.js / src / demux / transmuxer-worker.ts View on Github external
export default function TransmuxerWorker (self) {
  const observer = new EventEmitter() as any;
  observer.trigger = (event, data) => {
    observer.emit(event, event, ...data);
  };

  observer.off = (event, ...data) => {
    observer.removeListener(event, ...data);
  };

  const forwardMessage = (ev, data) => {
    self.postMessage({ event: ev, data: data });
  };

  // forward events to main thread
  observer.on(Event.FRAG_DECRYPTED, forwardMessage);
  observer.on(Event.ERROR, forwardMessage);
github virtkick / http-master / src / HttpMasterWorker.js View on Github external
id = id.toString('base64');
      cb(null, store[id], null);
    },
    set: function(id, data, cb) {
      id = id.toString('base64');
      store[id] = data;
      // todo cleanup old ids
      if (cb)
        cb();
    }
  };
  this.tcpServers = {};
  this.servers = [];
}

HttpMasterWorker.prototype = Object.create(EventEmitter.prototype);

HttpMasterWorker.prototype.logNotice = function(msg) {
  this.emit('logNotice', msg);
};

HttpMasterWorker.prototype.logError = function(msg) {
  this.emit('logError', msg);
};

HttpMasterWorker.prototype.unbindAll = function(unbindFinished) {
  unbindAll.call(this, unbindFinished);
};

HttpMasterWorker.prototype.loadConfig = function(config, configLoaded) {
  var self = this;
github redibox / core / src / hooks / PubSubHook.js View on Github external
constructor() {
    super('pubsub');
    this._mountToCore = true;

    // all pubsub messages from redis are routed through this emitter
    // so we can send them to the correct handlers
    this._router = new EventEmitter();
  }
github rse / apollo-client-ws / src / apollo-client-ws.js View on Github external
reconnectattempts: number,
            reconnectdelay:    number
        }`, errors))
            throw new Error(`invalid options: ${errors.join("; ")}`)

        /*  initialize state variables  */
        this._ws   = null
        this._wsf  = null
        this._to   = null
        this._tx   = {}

        /*  provide hook latching sub-system  */
        this._latching = new Latching()

        /*  provide event emitter sub-system  */
        this._emitter  = new EventEmitter()
    }
github ChefSteps / react-native-declan / src / triggers / BaseTrigger.js View on Github external
cloneAnimator = (animator: React.Element<*>, index: number) => {
    const events = new EventEmitter();
    return React.cloneElement(animator, {
      ...(this.state.propertiesToAppend || {}),
      // eslint-disable-next-line react/no-array-index-key
      key: index,
      ref: ref => {
        this.animators[index] = {
          ref,
          events,
        };
        if (animator.ref) {
          animator.ref(ref);
        }
      },
      onFinish: ({ finished }) => {
        if (animator.props.onFinish) {
          animator.props.onFinish({ finished });
github oasislabs / oasis.js / packages / gateway / src / index.ts View on Github external
public subscribe(request: SubscribeRequest): any {
    const events = new EventEmitter();
    this.session
      .request(SubscribeApi.method, SubscribeApi.url, {
        events: ['logs'],
        filter: urlEncodeFilter(request.filter!),
      })
      .then(response => {
        if (response.id === undefined || response.id === null) {
          throw new Error(`subscription failed: ${response}`);
        }
        // Store the event -> queueId mapping so that we can unsubscribe later.
        this.subscriptions.set(request.event, response.id);
        PollingService.instance({
          url: this.url,
          session: this.session,
          queueId: response.id,
        }).subscribe(response.id, (event: any) => {
github ninabreznik / voting-ethereum-contract / node_modules / web3-core-subscriptions / src / subscription.js View on Github external
EventEmitter.call(this);

    this.id = null;
    this.callback = null;
    this.arguments = null;
    this._reconnectIntervalId = null;

    this.options = {
        subscription: options.subscription,
        type: options.type,
        requestManager: options.requestManager
    };
}

// INHERIT
Subscription.prototype = Object.create(EventEmitter.prototype);
Subscription.prototype.constructor = Subscription;


/**
 * Should be used to extract callback from array of arguments. Modifies input param
 *
 * @method extractCallback
 * @param {Array} arguments
 * @return {Function|Null} callback, if exists
 */

Subscription.prototype._extractCallback = function (args) {
    if (_.isFunction(args[args.length - 1])) {
        return args.pop(); // modify the args array!
    }
};
github vanwagonet / middle-router / lib / router.js View on Github external
writable: true,
    value: fn
  }
}

function lazyLoad (step) {
  var self = this
  if (self.loaded) return self.fn(step)
  return Promise.resolve(self.fn(step)).then(function (fn) {
    if (fn instanceof Router) fn = middleRun(fn.middleware)
    self.loaded = true
    return (self.fn = fn)(step)
  })
}

Router.prototype = Object.create(EventEmitter.prototype, {

  start: method(function start () {
    if (this.isListening) this.stop() // remove previous listeners
    this.isListening = true
    this.unlisten = history.listen(this)
    return this.routing
  }),

  stop: method(function stop () {
    if (this.isListening) {
      this.isListening = false
      this.unlisten()
      this.unlisten = null
    }
    return this.routing
  }),
github klaytn / caver-js / packages / caver-core-subscriptions / src / subscription.js View on Github external
function Subscription(options) {
    EventEmitter.call(this)

    this.id = null
    this.callback = null
    this.arguments = null
    this._reconnectIntervalId = null

    this.options = {
        subscription: options.subscription,
        type: options.type,
        requestManager: options.requestManager,
    }
}

Subscription.prototype = Object.create(EventEmitter.prototype, {
    constructor: { value: Subscription },
})

/**
 * Should be used to extract callback from array of arguments. Modifies input param
 *
 * @method extractCallback
 * @param {Array} arguments
 * @return {Function|Null} callback, if exists
 */
Subscription.prototype._extractCallback = function(args) {
    if (_.isFunction(args[args.length - 1])) {
        return args.pop() // modify the args array!
    }
}

eventemitter3

EventEmitter3 focuses on performance while maintaining a Node.js AND browser compatible interface.

MIT
Latest version published 2 years ago

Package Health Score

79 / 100
Full package analysis