uevents.js
Micro events library for javascript. It works in the browser and has support
for CommonJS and AMD loading built in. It can also be used on the server
through node.js
, but for most applications usage of the native
events
API should suffice.
This library has no external dependencies and weights less than 1kb when
minified and gziped.
Complete API documentation is available here.
Basic Usage
You can create a new uevents object on which you can register callbacks
for named events, and unregister callbacks for named events, and trigger
events.
var obj = new uevents();
obj.on('signal', function (a, b) {
console.log("a: " + a + ", b: " + b);
});
obj.trigger('signal', 'A', 'B');
obj.trigger('signal', 5, 6);
obj.off('signal');
obj.trigger('signal', 'A', 'B');
You can also extend an existing object to allow it to emit and receive
events using the same API.
var obj = new ComplicatedCustomObject();
uevents.extend(obj);
obj.on('signal', function () {
console.log('signal emitted');
});
obj.trigger('signal');