Skip to content

Instantly share code, notes, and snippets.

@alissoncs
Last active May 9, 2020 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alissoncs/8866cbfe583b61d8034a829a25f32215 to your computer and use it in GitHub Desktop.
Save alissoncs/8866cbfe583b61d8034a829a25f32215 to your computer and use it in GitHub Desktop.
Event.js
var Event = function() {
var callbacks = {};
function emit(name, params) {
if (callbacks[name]) {
callbacks[name].map(function(item) {
item(params);
});
}
}
function subscribe(name, callback) {
if (!callbacks[name]) callbacks[name] = [];
callbacks[name].push(callback);
}
function unlisten(name, callback) {
if (callbacks[name]) {
callbacks[name].slice(callbacks[name].indexOf(callback), 1)
}
}
return {
emit: emit,
unsubscribe: subscribe,
subscribe: subscribe,
};
}
var awardsEvents = new Event();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment