Skip to content

Commit

Permalink
fix: add judge about event null and length
Browse files Browse the repository at this point in the history
  • Loading branch information
skie1997 committed Oct 25, 2023
1 parent c1fcfb9 commit 0d0c279
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/vchart/src/core/vchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,19 +997,22 @@ export class VChart implements IVChart {
this._event?.on(eType as any, query as any, handler as any);
}
off(eType: string, handler?: EventCallback<EventParams>): void {
if (!this._userEvents || this._userEvents.length === 0) {
return;
}
if (handler) {
const index = this._userEvents?.findIndex(e => e.eType === eType && e.handler === handler);
const index = this._userEvents.findIndex(e => e.eType === eType && e.handler === handler);
if (index >= 0) {
this._userEvents.splice(index, 1);
this._event?.off(eType, handler);
}
} else {
this._userEvents?.forEach(e => {
this._userEvents.forEach(e => {
if (e.eType === eType) {
this._event?.off(eType, e.handler);
}
});
this._userEvents = this._userEvents?.filter(e => e.eType !== eType);
this._userEvents = this._userEvents.filter(e => e.eType !== eType);
}
}

Expand Down

0 comments on commit 0d0c279

Please sign in to comment.