Last active
May 9, 2020 19:56
-
-
Save alissoncs/8866cbfe583b61d8034a829a25f32215 to your computer and use it in GitHub Desktop.
Event.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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