Skip to content

Instantly share code, notes, and snippets.

@craigp
Last active August 29, 2015 14:09
Show Gist options
  • Save craigp/e0a3e634a7dbcaffb2e5 to your computer and use it in GitHub Desktop.
Save craigp/e0a3e634a7dbcaffb2e5 to your computer and use it in GitHub Desktop.
define(['common', 'async'], function(common, async) {
'use strict';
function Emitter() {
this.events = {};
}
Emitter.prototype.emit = function(event, payload) {
if (this.events[event]) {
async.each(function(listener) {
listener.call(this, payload);
}, function() {
// finalizer?
});
}
};
Emitter.prototype.bind = function(event, listener) {
if (!this.events[event])
this.events[event] = [];
this.events[event].push(listener);
};
function makeEmitter(derived) {
common.__extends(derived, Emitter);
}
return {
extend: makeEmitter
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment