diff --git a/packages/store/src/derived.ts b/packages/store/src/derived.ts index 2731974..9e22878 100644 --- a/packages/store/src/derived.ts +++ b/packages/store/src/derived.ts @@ -51,22 +51,22 @@ export class Derived { prevDerivesForStore.add(dep) storeToDerived.set(store, prevDerivesForStore) } - deps.forEach((dep) => { + for (const dep of deps) { if (dep instanceof Derived) { derivedToStore.set(dep, dep.rootStores) - dep.rootStores.forEach((store) => { + for (const store of dep.rootStores) { this.rootStores.add(store) updateStoreToDerived(store, dep) - }) + } } else if (dep instanceof Store) { this.rootStores.add(dep) updateStoreToDerived(dep, this as Derived) } - }) + } let __depsThatHaveWrittenThisTick: Deps = [] - deps.forEach((dep) => { + for (const dep of deps) { const isDepAStore = dep instanceof Store let relatedLinkedDerivedVals: null | Set> = null @@ -92,7 +92,7 @@ export class Derived { }) this._subscriptions.push(unsub) - }) + } } get state() { @@ -100,7 +100,9 @@ export class Derived { } cleanup = () => { - this._subscriptions.forEach((cleanup) => cleanup()) + for (const cleanup of this._subscriptions) { + cleanup() + } }; [Symbol.dispose]() { diff --git a/packages/store/src/store.ts b/packages/store/src/store.ts index 216918c..5674496 100644 --- a/packages/store/src/store.ts +++ b/packages/store/src/store.ts @@ -52,10 +52,10 @@ export class Store< _flush = () => { if (this._batching) return const flushId = ++this._flushing - this.listeners.forEach((listener) => { - if (this._flushing !== flushId) return + for (const listener of this.listeners) { + if (this._flushing !== flushId) continue listener() - }) + } } batch = (cb: () => void) => {