Node's events module in the browser.
This is a wrapper around component/emitter that is api-compatible with node's events module. It also is a fork of juliangruber/events that adds uses node.js events when running on the server.
Events Node.js v0.8.11 Manual & Documentation
Install with component(1)
$ component install intesso/events
node.js events api:
var EventEmitter = require('events').EventEmitter;
var ee = new EventEmitter();
ee.on('foo', function(data) {
console.log('foo received', data);
})
ee.emit('foo', 'bar');
// -> 'foo received bar'
Another example with the component-emitter api:
function Obj() {
this.name = "Obj";
}
var Events = require('events');
Events(Obj.prototype);
obj = new Obj();
obj.addListener('foo', function(data) {
console.log('foo received', data);
})
obj.emit('foo', 'bar');
// -> 'foo received bar'
(MIT)