mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move tracker to telemetry extension (#1092)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
a478143423
commit
c566c85351
27 files changed
+472
-117
No files matched your search
@@ -1,40 +0,0 @@
|
||||
// Custom event emitter
|
||||
|
||||
interface Options {
|
||||
once?: boolean; // call once and remove
|
||||
prepend?: boolean; // put listener to the beginning
|
||||
}
|
||||
|
||||
type Callback<D extends [...any[]]> = (...data: D) => void | boolean;
|
||||
|
||||
export class EventEmitter<D extends [...any[]]> {
|
||||
protected listeners = new Map<Callback<D>, Options>();
|
||||
|
||||
addListener(callback: Callback<D>, options: Options = {}) {
|
||||
if (options.prepend) {
|
||||
const listeners = [...this.listeners];
|
||||
listeners.unshift([callback, options]);
|
||||
this.listeners = new Map(listeners);
|
||||
}
|
||||
else {
|
||||
this.listeners.set(callback, options);
|
||||
}
|
||||
}
|
||||
|
||||
removeListener(callback: Callback<D>) {
|
||||
this.listeners.delete(callback);
|
||||
}
|
||||
|
||||
removeAllListeners() {
|
||||
this.listeners.clear();
|
||||
}
|
||||
|
||||
emit(...data: D) {
|
||||
[...this.listeners].every(([callback, options]) => {
|
||||
if (options.once) this.removeListener(callback);
|
||||
const result = callback(...data);
|
||||
if (result === false) return; // break cycle
|
||||
return true;
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ export * from "../../common/utils"
|
||||
|
||||
export * from "./cssVar"
|
||||
export * from "./cssNames"
|
||||
export * from "./eventEmitter"
|
||||
export * from "../../common/event-emitter"
|
||||
export * from "./downloadFile"
|
||||
export * from "./prevDefault"
|
||||
export * from "./createStorage"
|
||||
|
||||
Reference in new issue
Block a user