npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

event-emitter-es6

v1.1.5

Published

Small event emitter for using in es6 and plain js

Downloads

18,919

Readme

event-emitter-es6

A small event emitter library. Works in the browser and in Node. Can be used with es6 inheritance or as stand-alone lib.

Inspired by the tiny-emitter package on npm.

For more information you can see jsdoc info in index.es6 file.

Very simply applies to express.

Install

Node

npm install event-emitter-es6 --save

Browser

bower install event-emitter-es6 --save
<script src="bower_components/event-emitter-es6/dist/event-emitter.min.js"></script>

or apply via express

var express = require('express');
var app = express();

<... your code here ...>

app.use( require('event-emitter-es6/router') );
<script src="event-emitter-es6/event-emitter.min.js"></script>

Usage

Node

var EventEmitter = require('event-emitter-es6');
var emitter = new Emitter();

emitter.on('some-event', function listener1 (param1, param2, param3) {
  console.info('listener1', param1, param2, param3);
});
emitter.on('some-event', function listener2 (param1, param2, param3) {
  console.info('listener2', param1, param2, param3);
});
emitter.emit('some-event', 'some-val1', 'some-val2', 'some-val3');

Browser

var emitter = new EventEmitter();

emitter.on('some-event', function listener1 (param1, param2, param3) {
  console.info('listener1', param1, param2, param3);
});

emitter.on('some-event', function listener2 (param1, param2, param3) {
  console.info('listener2', param1, param2, param3);
});

emitter.emit('some-event', 'some-val1', 'some-val2', 'some-val3');

ES6

class SomeEmittingClass extends EventEmitter {
  constructor() {
    super();
  }
  
  fireExampleEvent() {
    this.emit('some-event', 'some-val1', 'some-val2', 'some-val3');
  }
}

var emittingInstance = new SomeEmittingClass();

emittingInstance.on('some-event', function listener1 (param1, param2, param3) {
  console.info('listener1', param1, param2, param3);
});
emittingInstance.on('some-event', function listener2 (param1, param2, param3) {
  console.info('listener2', param1, param2, param3);
});
emittingInstance.fireExampleEvent();

Instance Methods

constructor([opts])

An option can be passed to constructor

  • opts - settings object for create event emitter
  • opts.emitDelay - delay in ms to emit event. If passed 0 - all events emits synchronously. By default = 10
  • opts.strictMode - when emit event with no listeners - fires error. By default = false

destroy()

Completely destroys event emitter.

on(event, callback)

Subscribe to an event

  • event - the name of the event to subscribe to
  • callback - the function to call when event is emitted (for transfer context use bind method of Function.prototype)

once(event, callback)

Subscribe to an event only once

  • event - the name of the event to subscribe to
  • callback - the function to call when event is emitted (for transfer context use bind method of Function.prototype)

off(event[, callback])

Unsubscribe from an event or all events. If no callback is provided, it unsubscribes you from all events.

  • event - the name of the event to unsubscribe from
  • callback - the function used when binding to the event. If you used function with bind method - must be passed the same function, that was getted after binding.

emit(event[, ...arguments])

Trigger a named event

  • event - the event name to emit
  • arguments... - any number of arguments to pass to the event subscribers

emitSync(event[, ...arguments])

Trigger a named event immediate (even the emitter was created as async instance)

  • event - the event name to emit
  • arguments... - any number of arguments to pass to the event subscribers

Build

Build (Browserifies, and minifies)

npm install
npm run build

Test

Test

npm install
npm run test

Change list

Version 1.1.5

  • destroy() method of class

Version 1.1.4

  • All code covered with tests