From 3f5b999dd93239655a03d5a35f869d392633af1c Mon Sep 17 00:00:00 2001 From: jimmychai Date: Tue, 28 Nov 2023 13:47:07 +0800 Subject: [PATCH] =?UTF-8?q?BI-139113=20fix:=20=E4=BC=98=E5=8C=96subs?= =?UTF-8?q?=E9=94=80=E6=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit ceebbfad94c130a90498bd7dd21b3503dbac2d99) --- packages/fineui/src/fix/fix.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/fineui/src/fix/fix.js b/packages/fineui/src/fix/fix.js index a28f5e4a8..ddc37b044 100644 --- a/packages/fineui/src/fix/fix.js +++ b/packages/fineui/src/fix/fix.js @@ -7,7 +7,7 @@ const pendingCleanupDeps = []; const cleanupDeps = () => { for (let i = 0; i < pendingCleanupDeps.length; i++) { const dep = pendingCleanupDeps[i]; - dep.subs = dep.subs.filter(s => s); + dep.subs = dep.subs.filter(s => dep.subsSet.has(s.id)); dep._pending = false; } pendingCleanupDeps.length = 0; @@ -23,14 +23,16 @@ class Dep { this.id = uid++; this._pending = false; this.subs = []; + this.subsSet = new Set(); } addSub(sub) { this.subs.push(sub); + this.subsSet.add(sub.id); } removeSub(sub) { - this.subs[this.subs.indexOf(sub)] = null; + this.subsSet.delete(sub.id); if (!this._pending) { this._pending = true; pendingCleanupDeps.push(this); @@ -45,7 +47,7 @@ class Dep { notify(options) { // stabilize the subscriber list first - const subs = this.subs.filter(s => s); + const subs = this.subs.filter(s => this.subsSet.has(s.id)); for (let i = 0, l = subs.length; i < l; i++) { subs[i].update(options); }