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

eventhandler

v2.1.0

Published

Universal module defined event handler built in JavaScript for maximum speed.

Downloads

1,398

Readme

eventhandler

Universal module defined to be used with requirejs, node, commonjs, or global scoped if no module loader is used.

All files in the dist folder are minified for production use. All files in the src directory are the source code for development use.

  • nodejs
  • npm install
  • npm install -g gulp

gulp test

Each process is dependent upon the previous. If one fails the build process exits.

  • gulp
  • gulp test (Unit specifications)
  • gulp build (Test, folder clean-ups, minification, source maps, renaming)
  • gulp deploy (Test, build, versioning)

npm: npm install eventhandler bower: bower install eventhandler

var eventHandler1 = new EventHandler();
var eventHandler2 = new EventHandler();
var eventHandler3 = new EventHandler();
console.log('Subscribing EventHandler 2 to EventHandler 1.');
eventHandler2.subscribe(eventHandler1);
console.log('Subscribing EventHandler 3 to EventHandler 1.');
eventHandler3.subscribe(eventHandler1);

var data = {
    superhero: "Batman",
    sidekick: "Robin"
};

console.log('Adding a random event listener to EventHandler 1.');
eventHandler1.on('bang', function(data) {
    console.log('cb eventHandler: 1');
    console.log('this = ' + this);
    console.log(data.superhero + ' (POW!), ' + data.sidekick + ' (BOOM!)');
});

eventHandler2.on('bang', function(data) {
    console.log('cb eventHandler: 2');
    console.log('this = ' + this);
    console.log(data.superhero + ' (BAM!), ' + data.sidekick + ' (OUCH!)');
});

eventHandler3.on('bang', function(data) {
    console.log('cb eventHandler: 3');
    console.log('this = ' + this);
    console.log(data.superhero + ' (KABLOOM!), ' + data.sidekick + ' (KICK!)');
});

eventHandler1.emit('bang', data);

console.log('EventHandler 2 is unsubscribing from EventHandler 1.');
eventHandler2.unsubscribe(eventHandler1);

eventHandler1.emit('bang', data);

console.log('Removing all event listeners from EventHandler 1.');
eventHandler1.removeAllEventListeners('bang');

eventHandler1.emit('bang', data);

// Add some more subscribers for testing.
console.log('Subscribing EventHandler 2 to EventHandler 1.');
eventHandler2.subscribe(eventHandler1);
console.log('Removing all subscribers.');
eventHandler1.removeAllSubscribers();
eventHandler1.emit('bang', data);

// Add some more subscribers for testing.
console.log('Subscribing EventHandler 2 to EventHandler 1.');
eventHandler2.subscribe(eventHandler1);
console.log('Removing all subscriptions for EventHandler 2.');
eventHandler2.removeAllSubscriptions();
eventHandler1.emit('bang', data);
  • removeEventListener and unsubscribe now work properly. In turn this leads to removeAllSubscribers working.
  • Added removeAllSubscriptions which will remove all hooks from every other EventHandler that it's subscribed to.
  • Enhanced performance of unsubscribe and removeEventListener even though they're rarely used but in some situations where something is adding and removing callbacks every process this is huge.
  • Changed the name of the eventhandler.js to EventHandler.js. Captial file names for classes just make more sense to me so I can distiguish bundles and frameworks from single classes.
  • Added subscribe and unsubscribe. Each EventHandler can subscribe to one another. The event handler that subscribes to the other will emit the events in sync with the one subscribed to.
  • Change the "main" property in package.json to point to the src/EventHandler.js since node is what uses it and needs the source code for debugging. If using things like Browserify it won't matter since the minification process happens after all files are compiled into one. This is better for everyone.
  • Fixed sourcemap linking for minified files. This is also fixed as part of the build process to automate proper sourcemap creation and linking.