Skip to content

Instantly share code, notes, and snippets.

@calindotgabriel
Created September 13, 2017 12:53
Show Gist options
  • Save calindotgabriel/0e67eb254cca4cd350b3c0751c1232f9 to your computer and use it in GitHub Desktop.
Save calindotgabriel/0e67eb254cca4cd350b3c0751c1232f9 to your computer and use it in GitHub Desktop.
function EventEmitter () {
events = {}
function publish(type, payload) {
callbacks = events[type]
callbacks.forEach(c => {
c(payload)
})
}
function subscribe(type, callback) {
events[type].push(callback)
}
function unsubscribe(type, callback) {
callbacks = events[type]
events[type] = callbacks.filter(c => !c.compare(callback))
}
}
new EventEmitter('login', () => {
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment