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.
In All Seriousness
Sister is 0.5kb event emitter that does three things:
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
emitterInstance of the
eventName of the event.
handlerA function to execute when the event is triggered.
eventlisteners (in sequence) with the supplied argument.
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
There are several existing alternatives that you might want to consider before starting to write your own implementation of an event emitter.