mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup <EventEmitter>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ad8dc8a7c9
commit
0587a45cbe
@ -33,12 +33,8 @@ export class EventEmitter<D extends [...any[]]> {
|
|||||||
|
|
||||||
addListener(callback: Callback<D>, options: Options = {}) {
|
addListener(callback: Callback<D>, options: Options = {}) {
|
||||||
if (options.prepend) {
|
if (options.prepend) {
|
||||||
const listeners = [...this.listeners];
|
this.listeners = new Map([[callback, options], ...this.listeners]);
|
||||||
|
} else {
|
||||||
listeners.unshift([callback, options]);
|
|
||||||
this.listeners = new Map(listeners);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.listeners.set(callback, options);
|
this.listeners.set(callback, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,12 +48,14 @@ export class EventEmitter<D extends [...any[]]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit(...data: D) {
|
emit(...data: D) {
|
||||||
[...this.listeners].every(([callback, options]) => {
|
for (const [callback, { once }] of this.listeners) {
|
||||||
if (options.once) {
|
if (once) {
|
||||||
this.removeListener(callback);
|
this.removeListener(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
return callback(...data) !== false;
|
if (callback(...data) === false) {
|
||||||
});
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user