#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');
function Fruit(name) {
this.name = name;
Emitter.call(this);
}
Fruit.prototype = new Emitter;
Fruit.prototype.test = function () {
this.emit('test', this.name);
};
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);
});
apple.test();
apple.off('test');
##License
MIT
If you like this follow @HenrikJoreteg on twitter.