fix: remove parent from emitter callback

This commit is contained in:
pylixonly 2024-10-12 23:19:55 +08:00
parent 019fdc28b3
commit fe937a4ab5
2 changed files with 2 additions and 6 deletions

View file

@ -21,7 +21,6 @@ export function createProxy(target: any = {}): { proxy: any; emitter: Emitter; }
if (value !== undefined && value !== null) {
emitter.emit("GET", {
parent: parentTarget,
path: newPath,
value,
});
@ -56,7 +55,6 @@ export function createProxy(target: any = {}): { proxy: any; emitter: Emitter; }
}
emitter.emit("SET", {
parent: parentTarget,
path: [...path, prop],
value: target[prop],
});
@ -70,7 +68,6 @@ export function createProxy(target: any = {}): { proxy: any; emitter: Emitter; }
if (success)
emitter.emit("DEL", {
value,
parent: parentTarget,
path: [...path, prop],
});
return success;

View file

@ -8,8 +8,7 @@ export type EmitterEvent = "SET" | "GET" | "DEL";
export interface EmitterListenerData {
path: string[];
value: any;
parent: any;
value?: any;
}
export type EmitterListener = (
@ -17,7 +16,7 @@ export type EmitterListener = (
data: EmitterListenerData | any
) => any;
export type EmitterListeners = Record<string, Set<EmitterListener>>
export type EmitterListeners = Record<string, Set<EmitterListener>>;
export class Emitter {
listeners = Object.values(Events).reduce<EmitterListeners>(