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

ev-emitter

v2.1.2

Published

lil' event emitter

Downloads

1,653,771

Readme

EvEmitter

Lil' event emitter — add a little pub/sub

EvEmitter adds publish/subscribe pattern to a browser class. It's a smaller version of Olical/EventEmitter. That EventEmitter is full featured, widely used, and great. This EvEmitter has just the base event functionality to power the event API in libraries like Isotope, Flickity, Masonry, and imagesLoaded.

API

// class inheritence
class MyClass extends EvEmitter {}

// mixin prototype
Object.assign( MyClass.prototype, EvEmitter.prototype );

// single instance
let emitter = new EvEmitter();

on

Add an event listener.

emitter.on( eventName, listener )
  • eventName - String - name of the event
  • listener - Function

off

Remove an event listener.

emitter.off( eventName, listener )

once

Add an event listener to be triggered only once.

emitter.once( eventName, listener )

emitEvent

Trigger an event.

emitter.emitEvent( eventName, args )
  • eventName - String - name of the event
  • args - Array - arguments passed to listeners

allOff

Removes all event listeners.

emitter.allOff()

Code example

// create event emitter
var emitter = new EvEmitter();

// listeners
function hey( a, b, c ) {
  console.log( 'Hey', a, b, c )
}

function ho( a, b, c ) {
  console.log( 'Ho', a, b, c )
}

function letsGo( a, b, c ) {
  console.log( 'Lets go', a, b, c )
}

// bind listeners
emitter.on( 'rock', hey )
emitter.on( 'rock', ho )
// trigger letsGo once
emitter.once( 'rock', letsGo )

// emit event
emitter.emitEvent( 'rock', [ 1, 2, 3 ] )
// => 'Hey', 1, 2, 3
// => 'Ho', 1, 2, 3
// => 'Lets go', 1, 2, 3

// unbind
emitter.off( 'rock', ho )

emitter.emitEvent( 'rock', [ 4, 5, 6 ] )
// => 'Hey' 4, 5, 6

Browser support

EvEmitter v2 uses ES6 features like for...of loops and class definition as such it supports Chrome 49+, Firefox 45+, Safari 9+, and Edge 13+.

For older browser support, use EvEmitter v1.

License

EvEmitter is released under the MIT License. Have at it.