asarfuckery/electronasar/stable/renderer/extensions/event.js

27 lines
420 B
JavaScript
Raw Normal View History

2019-01-17 18:22:05 +00:00
'use strict'
class Event {
constructor () {
this.listeners = []
}
addListener (callback) {
this.listeners.push(callback)
}
removeListener (callback) {
const index = this.listeners.indexOf(callback)
if (index !== -1) {
this.listeners.splice(index, 1)
}
}
emit (...args) {
for (const listener of this.listeners) {
listener(...args)
}
}
}
module.exports = Event