|
|
@ -7,7 +7,7 @@ const pendingCleanupDeps = []; |
|
|
|
const cleanupDeps = () => { |
|
|
|
const cleanupDeps = () => { |
|
|
|
for (let i = 0; i < pendingCleanupDeps.length; i++) { |
|
|
|
for (let i = 0; i < pendingCleanupDeps.length; i++) { |
|
|
|
const dep = pendingCleanupDeps[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; |
|
|
|
dep._pending = false; |
|
|
|
} |
|
|
|
} |
|
|
|
pendingCleanupDeps.length = 0; |
|
|
|
pendingCleanupDeps.length = 0; |
|
|
@ -23,14 +23,16 @@ class Dep { |
|
|
|
this.id = uid++; |
|
|
|
this.id = uid++; |
|
|
|
this._pending = false; |
|
|
|
this._pending = false; |
|
|
|
this.subs = []; |
|
|
|
this.subs = []; |
|
|
|
|
|
|
|
this.subsSet = new Set(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addSub(sub) { |
|
|
|
addSub(sub) { |
|
|
|
this.subs.push(sub); |
|
|
|
this.subs.push(sub); |
|
|
|
|
|
|
|
this.subsSet.add(sub.id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removeSub(sub) { |
|
|
|
removeSub(sub) { |
|
|
|
this.subs[this.subs.indexOf(sub)] = null; |
|
|
|
this.subsSet.delete(sub.id); |
|
|
|
if (!this._pending) { |
|
|
|
if (!this._pending) { |
|
|
|
this._pending = true; |
|
|
|
this._pending = true; |
|
|
|
pendingCleanupDeps.push(this); |
|
|
|
pendingCleanupDeps.push(this); |
|
|
@ -45,7 +47,7 @@ class Dep { |
|
|
|
|
|
|
|
|
|
|
|
notify(options) { |
|
|
|
notify(options) { |
|
|
|
// stabilize the subscriber list first
|
|
|
|
// 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++) { |
|
|
|
for (let i = 0, l = subs.length; i < l; i++) { |
|
|
|
subs[i].update(options); |
|
|
|
subs[i].update(options); |
|
|
|
} |
|
|
|
} |
|
|
|