Browse Source

Merge pull request #257001 in DEC/fineui from master to feature/x

* commit '3cd249dda4072838e967d78c10c3f9a0aef7ebb2':
  BI-139113 fix: 优化subs销毁
master
superman 1 year ago
parent
commit
680056b046
  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