2019-10-01 13:49:56 +00:00
|
|
|
'use strict';
|
2019-01-17 18:22:05 +00:00
|
|
|
class Event {
|
2019-10-01 13:49:56 +00:00
|
|
|
constructor() {
|
|
|
|
this.listeners = [];
|
2019-01-17 18:22:05 +00:00
|
|
|
}
|
2019-10-01 13:49:56 +00:00
|
|
|
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);
|
|
|
|
}
|
2019-01-17 18:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-01 13:49:56 +00:00
|
|
|
module.exports = Event;
|