Foundation for your emitter implementation.
I have observed that there is a tendency to write your own implementation of event emitter. I have written a starter pack for those wishing to improve upon existing variations of event emitter implementation.
Please submit your implementation to the index when you are done.
Sister is 0.5kb event emitter that does three things: on, off and trigger. It performs well (~18,313,548 operations/sec in browser). If you need something more advanced, consider one of the existing, mature alternatives.
Download using NPM:
npm install sister --save
Download using Bower:
bower install sister --save
In browser, use gajus.Sister window object.
emitter Instance of the Sister() object.event Name of the event.handler A function to execute when the event is triggered.listener Event listener.emitter.on(event, handler)handler for event.listener.emitter.off(listener)listener.emitter.trigger(event, data)event listeners (in sequence) with the supplied argument.emitter.var Sister = require('sister'),
emitter = Sister(),
listener;
listener = emitter.on('foo', console.log);
emitter.trigger('foo', 'bar');
emitter.off(listener);
emitter.trigger('foo', 'baz');
This example will print "bar" in the console.log.
There are several existing alternatives that you might want to consider before starting to write your own implementation of an event emitter.