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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hoopla

v0.1.1

Published

An event dispatcher with priorities

Readme

Hoopla

Build Status

An event dispatcher for JavaScript that knows its priorities.

Node's event-emitter package is fine for simple events, but if you get more than a few listeners to a single event, it becomes difficult to manage. Hoopla allows you to set priorities for your event handlers so they get called in a certain order.

Creating a dispatcher

var Hoopla = require('hoopla');
var dispatcher = new Hoopla();

Basic events

Add listeners with the addListener method and fire events with dispatch.

dispatcher.addListener('init', function() {
    console.log('it was initialized!');
});

dispatcher.dispatch('init');
// Prints 'it was initialized!'

Event priority

Hoopla allows you to set an unlimited number of event listeners for any event. By default, they all have a priority of 0, so they get handled in the order they are registered. If you give a handler a negative or positive priority, Hoopla will call the handlers in order from least to greatest.

dispatcher.addListener('init', function() {
    console.log('default init handler');
});

dispatcher.addListener('init', function() {
    console.log('early init handler');
}, -5);

dispatcher.addListener('init', function() {
    console.log('late init handler');
}, 3);

dispatcher.dispatch('init');
// Prints 'early init handler', 'default init handler', 'late init handler'

Event objects

Hoopla passes an Event object to your event listeners. Events are objects that have a name, and attributes.

dispatcher.addListener('route', function(event) {
    if (event.getName() === 'route') {
        console.log(event.get('foo'));
    } else {
        event.set('foo', 3);
    }
});

If you pass an object as the second argument to dispatch, Hoopla will set its properties as attributes on the event object.

dispatcher.addListener('init', function(event) {
    console.log(event.get('foo')); // prints 'foo value'
});

dispatcher.dispatch('init', {foo: 'foo value'});

Stopping propagation

Event listeners can stop propagation for an event meaning that event will not trigger any more listeners.

dispatcher.addListener('init', function(event) {
   event.stopPropagation();
});

dispatcher.addListener('init', function() {
    // will not be called
}, 1);

dispatcher.dispatch('init');

Creating an event object

If you wish, you can create an event object manually and pass it to the dispatch method.

// Create an event with dispatcher.createEvent
var eventA = dispatcher.createEvent('foo', {a: 'a'});
// or create an event with the Event constructor
var eventB = new Hoopla.Event('bar', {b: 'b'});

dispatcher.dispatch(eventA);
dispatcher.dispatch(eventB);

You can create custom events objects. An event object must have getName and isPropagationStopped methods.

var fooEvent = {
    getName: function() {
        return 'foo';
    },
    isPropagationStopped: function() {
        return false;
    }
};
dispatcher.dispatch(fooEvent);