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

after-events

v1.0.2

Published

Event Emitter with hooks for listener return values

Downloads

7

Readme

After Event Emitter

npm install after-events

Publisher/Subscriber Pattern implementation.

Differences from Node's EventEmitter

  • .after(cb) method (see below)
  • Listeners that throw errors are caught and logged to console.
  • Listeners happen during their own turn.
  • Listener can only listen a maximum of one time with .on()
  • "removeListener" is called "off"
  • No way to see if the listener is listening. (unused)
  • No "addListener" alias
  • No domains (unused)
  • No erroring on unhandled error event. (unused)
  • No maximum listener count. (unused)
  • No prototype/No new needed to create.

If you need one of the features this lacks that is marked unused, feel free to send a pull request/file an issue.

after(callback: function (err: Error U undefined, res: Any U undefined, type: String, ...args: Any)): undefined

  • callback is ran after every listener returns.
  • First parameter to the callback is the error/rejected value of the listener, if there is one.
  • Second parameter to the callback is the return value of the listener, if there is one.
  • The rest of the parameters are the parameters sent to the .emit() that triggered the listener.
  • Calling it multiple times adds more callbacks to be called in order of addition.

Example

// This is really contrived!

var eventEmitter = require('after-events');
var format = require('util').format;

eventEmitter.after(function (err, ret, eventname, eventarg) {
    console.log(format('%s + 1 = %s', eventarg, ret));
});

eventEmitter.on('number', function (number) {
    return number + 1;
});

eventEmitter.emit('number', 2);
// Console logs '2 + 1 = 3'

eventEmitter.emit('number', 5);
// Console.logs '5 + 1 = 6'

For a realistic example, see [https://github.com/Tennu/tennu/blob/master/lib/command-handler.js](Tennu's Command Handler).

Tests and Building

To build the test file, use ./fez.js.

To run the test file, use mocha test.js.