From 73c073cc112ca1c9ec1ae7975cd90a5cc4d76597 Mon Sep 17 00:00:00 2001 From: "lixuefei.1313" Date: Mon, 18 Sep 2023 12:01:38 +0800 Subject: [PATCH 1/3] feat: supports deleting all events of the corresponding type without passing through the handler when calling off --- packages/vchart/src/core/vchart.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index 6d9dc6623f..3bdff33597 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -958,9 +958,13 @@ 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 = this._userEvents.filter(e => e.eType !== eType); } this._event?.off(eType, handler); } From e4bf88398e75b4f1ab0a961e1d166be66f7bca48 Mon Sep 17 00:00:00 2001 From: "lixuefei.1313" Date: Mon, 18 Sep 2023 12:01:55 +0800 Subject: [PATCH 2/3] docs: update changlog of rush --- ...the-handler-when-calling-off_2023-09-18-04-01.json | 11 +++++++++++ ...the-handler-when-calling-off_2023-09-18-04-01.json | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 common/changes/@visactor/vchart/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json create mode 100644 common/changes/@visactor/vutils-extension/feat-support-without-passing-through-the-handler-when-calling-off_2023-09-18-04-01.json 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 From c07d8f50c9e94e02ba5d60c9bebda01c167f4831 Mon Sep 17 00:00:00 2001 From: "lixuefei.1313" Date: Mon, 18 Sep 2023 12:05:38 +0800 Subject: [PATCH 3/3] fix: only remove user event --- packages/vchart/src/core/vchart.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index 3bdff33597..6032a17996 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -964,9 +964,13 @@ export class VChart implements IVChart { 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); } // 状态相关方法