Remove unused code

This commit is contained in:
Evan Fiordeliso 2025-06-26 13:13:15 -04:00
parent 13f34801ca
commit d86e4affa2
2 changed files with 0 additions and 73 deletions

View File

@ -1,52 +0,0 @@
export class Event {
constructor(
public readonly type: string,
public readonly payload: Record<string, any> = {}
) {}
public toString(): string {
return `Event(type: ${this.type}, payload: ${JSON.stringify(
this.payload
)})`;
}
}
export type Constructor = new (...args: any[]) => any;
export let EventEmitter = <T extends Constructor>(Base: T) =>
class extends Base {
private listeners: Record<string, ((event: Event) => void)[]> = {};
public on(eventType: string, listener: (event: Event) => void): void {
if (!this.listeners[eventType]) {
this.listeners[eventType] = [];
}
this.listeners[eventType].push(listener);
}
public off(eventType: string, listener: (event: Event) => void): void {
if (!this.listeners[eventType]) return;
this.listeners[eventType] = this.listeners[eventType].filter(
(l) => l !== listener
);
}
public once(eventType: string, listener: (event: Event) => void): void {
const onceListener = (event: Event) => {
listener(event);
this.off(eventType, onceListener);
};
this.on(eventType, onceListener);
}
public emit(event: Event): void {
const listeners = this.listeners[event.type];
if (listeners) {
for (const listener of listeners) {
listener(event);
}
}
}
};

View File

@ -1,21 +0,0 @@
export function flatten(
obj: Record<string, any>,
prefix = ""
): Record<string, any> {
return Object.keys(obj).reduce((acc, key) => {
const value = obj[key];
const newKey = prefix ? `${prefix}.${key}` : key;
if (
typeof value === "object" &&
value !== null &&
!Array.isArray(value)
) {
Object.assign(acc, flatten(value, newKey));
} else {
acc[newKey] = value;
}
return acc;
}, {} as Record<string, any>);
}