diff --git a/common/changes/@visactor/vchart/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json b/common/changes/@visactor/vchart/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json new file mode 100644 index 0000000000..dae90019fa --- /dev/null +++ b/common/changes/@visactor/vchart/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "feat: supports deleting all events of the corresponding type without passing through the handler when calling off\n\n", + "type": "none", + "packageName": "@visactor/vchart" + } + ], + "packageName": "@visactor/vchart", + "email": "lixuef1313@163.com" +} \ No newline at end of file diff --git a/common/changes/@visactor/vutils-extension/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json b/common/changes/@visactor/vutils-extension/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json new file mode 100644 index 0000000000..dafab689b9 --- /dev/null +++ b/common/changes/@visactor/vutils-extension/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "feat: supports deleting all events of the corresponding type without passing through the handler when calling off\n\n", + "type": "patch", + "packageName": "@visactor/vutils-extension" + } + ], + "packageName": "@visactor/vutils-extension", + "email": "lixuef1313@163.com" +} \ No newline at end of file diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index 6d9dc6623f..6032a17996 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -958,11 +958,19 @@ export class VChart implements IVChart { this._event?.on(eType as any, query as any, handler as any); } off(eType: string, handler?: EventCallback): void { - const index = this._userEvents.findIndex(e => e.eType === eType && e.handler === handler); - if (index >= 0) { - this._userEvents.splice(index, 1); + if (handler) { + const index = this._userEvents.findIndex(e => e.eType === eType && e.handler === handler); + if (index >= 0) { + this._userEvents.splice(index, 1); + } + } else { + this._userEvents.forEach(e => { + if (e.eType === eType) { + this._event?.off(eType, e.handler); + } + }); + this._userEvents = this._userEvents.filter(e => e.eType !== eType); } - this._event?.off(eType, handler); } // 状态相关方法