Skip to content

Instantly share code, notes, and snippets.

@overthemike
Created April 2, 2019 18:40
Show Gist options
  • Save overthemike/3222b9ab827dd0c96b8deac89ddc91f6 to your computer and use it in GitHub Desktop.
Save overthemike/3222b9ab827dd0c96b8deac89ddc91f6 to your computer and use it in GitHub Desktop.
var I = (function(){
var events = {}
function subscribe(event, fn) {
if (events.hasOwnProperty(event)) {
events[event].push(fn)
} else {
events[event] = [fn]
}
}
function publish(event, data = {}) {
if (events.hasOwnProperty(event)) {
events[event].forEach(fn => fn(data))
}
}
return {
subscribe: subscribe,
publish: publish
}
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment