Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wildemitter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wildemitter

A super lightweight EventEmitter similar to what comes in Node.js, but with a support for wildcard events '*'

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34K
decreased by-18.09%
Maintainers
1
Weekly downloads
 
Created
Source

#WildEmitter

##What is it? A super lightweight EventEmitter similar to what comes in Node.js, but with a few specific differences:

  • works in the browser (using some type of CommonJS module adapter, like stitch or browserify)
  • support wildcard handlers: emitter.on('*', doSomething) or emitter.on('myNamespace*', doSomething)

This is largely based on the emitter in @visionmedia's UIKit. So, much props there. I just wanted it as a standalone on npm and with support for * handlers.

##How do I use it?

You can use it to add event capabilities to other objects you build like so:

var Emitter = require('./wildemitter');

// the example object we're making
function Fruit(name) {
    this.name = name;
    
    // call emitter with this context
    Emitter.call(this);
}

// inherit from Emitter
Fruit.prototype = new Emitter;

// a function that emits an events when called
Fruit.prototype.test = function () {
    this.emit('test', this.name);
};

// set up some test fruits
var apple = new Fruit('apple');

apple.on('*', function () {
    console.log('"*" handler called', arguments);
});

apple.on('te*', function () {
    console.log('"te*" handler called', arguments);
});

apple.on('test', function () {
    console.log('"test" handler called', arguments);
});

// calling the method that emits events.
apple.test();

// it should write the following the log:
/*
"test" handler called { '0': 'apple' }
"*" handler called { '0': 'test', '1': 'apple' }
"te*" handler called { '0': 'test', '1': 'apple' }
*/

// this will remove any handlers explicitly listening for 'test' events.
apple.off('test');

// calling our method again would this time only call the two wildcard handlers
// producing the following output
/*
"*" handler called { '0': 'test', '1': 'apple' }
"te*" handler called { '0': 'test', '1': 'apple' }
*/

##License MIT

If you like this follow @HenrikJoreteg on twitter.

Keywords

FAQs

Package last updated on 21 Aug 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc