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

emitters

v0.1.0

Published

Fancy node-compatible event emitters, including bubbling and singleton ready events.

Downloads

31

Readme

emitters

Fancy node-compatible event emitters, including bubbling and singleton ready events.

var emitters = require('emitters');

// Polyfill for a node-compatible EventEmitter.
var ee = new emitters.EventEmitter();

var count = 0
,   counter = function (evt){
        console.log("Count: "+(count++)+" because "+this+" fired "+evt);
    };

// An emitter that auto-invokes listeners if the "ready" event has already occurred.
var re = new emitters.ReadyEmitter();
re.on('ready', counter);

// Fires the ready event unless already ready.
re.ready(true); // -> count == 1

// Invokes our callback because we're already ready.
re.on('ready', counter); // -> count == 2

// Or...
re.ready(counter); // -> count == 3

// A ChainedEmitter bubbles events to its parent.
var c1 = new emitters.ChainedEmitter(ee)
,   c2 = new emitters.ChainedEmitter(c1)
,   c3 = new emitters.ChainedEmitter()
;

// You can also get/set the parent emitter later.
c3.parentEmitter(c1);

// So we're bubbling from c2 -> c1, c3 -> c1, and c1 -> ee; let's listen in.
ee.on('bonk', counter);
c1.on('bonk', counter);
c2.on('bonk', counter);
c3.on('bonk', counter);

c2.emit('bonk'); // -> We see c2, c1, and ee all recieve events, putting our counter to 6.

// Event handlers can stop propagaion by returning false.
c1.on('bonk', function (){
    console.log('STOP!');
    return false;
});

c3.emit('bonk'); // -> c3 and c1 both have listeners who will get the event...
// But the second listener we just registered will end the bubbling. (Even if the 
// listener were first, the rest of c1's listeners would be notified. Stopping 
// propagation prevents the event from moving *up*.)

Usage

For usage in node.js, install it via npm: npm install emitters.

A browser distribution is coming soon!

API

Coming soon — use the source, Luke!

Feedback

Find a bug or want to contribute? Open a ticket (or fork the source!) on github. You're also welcome to send me email at [email protected].

License

emitters was written by David Schoonover (in Coco, a dialect of CoffeeScript that compiles down to JavaScript). It is open-source software and freely available under the MIT License.