Browse Source

BI-139113 fix: 优化subs销毁

(cherry picked from commit ceebbfad94)
research/test
jimmychai 1 year ago
parent
commit
3f5b999dd9
  1. 8
      packages/fineui/src/fix/fix.js

8
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);
}

Loading…
Cancel
Save