Skip to content

Commit

Permalink
fix(data-source): 默认事件处理支持path为空字符串
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Jun 6, 2024
1 parent e1f8392 commit ac7bb93
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/data-source/src/observed-data/SimpleObservedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class SimpleObservedData extends ObservedData {
super();
this.data = initialData;
}

update(data: any, path?: string): void {
if (path) {
setValueByKeyPath(path, data, this.data);
Expand All @@ -23,16 +24,25 @@ export class SimpleObservedData extends ObservedData {
updateData: data,
path: path ?? '',
};
this.event.emit(path ?? '', changeEvent);

if (path) {
this.event.emit(path, changeEvent);
}

this.event.emit('', changeEvent);
}

on(path: string, callback: (newVal: any) => void): void {
this.event.on(path, callback);
}

off(path: string, callback: (newVal: any) => void): void {
this.event.off(path, callback);
}

getData(path: string) {
return path ? getValueByKeyPath(path, this.data) : this.data;
}

destroy(): void {}
}

0 comments on commit ac7bb93

Please sign in to comment.