electron/lib/renderer/extensions/event.ts

21 lines
406 B
TypeScript
Raw Normal View History

export class Event {
private listeners: Function[] = []
addListener (callback: Function) {
2016-06-16 16:51:54 +00:00
this.listeners.push(callback)
}
removeListener (callback: Function) {
2016-06-16 16:51:54 +00:00
const index = this.listeners.indexOf(callback)
if (index !== -1) {
this.listeners.splice(index, 1)
}
}
emit (...args: any[]) {
2016-06-16 16:51:54 +00:00
for (const listener of this.listeners) {
listener(...args)
}
}
}