2019-06-14 14:52:24 +00:00
|
|
|
export class Event {
|
|
|
|
private listeners: Function[] = []
|
2018-09-22 12:28:50 +00:00
|
|
|
|
2019-06-14 14:52:24 +00:00
|
|
|
addListener (callback: Function) {
|
2016-06-16 16:51:54 +00:00
|
|
|
this.listeners.push(callback)
|
|
|
|
}
|
|
|
|
|
2019-06-14 14:52:24 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 14:52:24 +00:00
|
|
|
emit (...args: any[]) {
|
2016-06-16 16:51:54 +00:00
|
|
|
for (const listener of this.listeners) {
|
|
|
|
listener(...args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|