Skip to content

Commit

Permalink
chore: migrate from forEach to for of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Feb 26, 2024
1 parent 87dd588 commit de55814
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions packages/store/src/derived.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ export class Derived<TState> {
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<unknown>)
}
})
}

let __depsThatHaveWrittenThisTick: Deps = []

deps.forEach((dep) => {
for (const dep of deps) {
const isDepAStore = dep instanceof Store
let relatedLinkedDerivedVals: null | Set<Derived<unknown>> = null

Expand All @@ -92,15 +92,17 @@ export class Derived<TState> {
})

this._subscriptions.push(unsub)
})
}
}

get state() {
return this._store.state
}

cleanup = () => {
this._subscriptions.forEach((cleanup) => cleanup())
for (const cleanup of this._subscriptions) {
cleanup()
}
};

[Symbol.dispose]() {
Expand Down
6 changes: 3 additions & 3 deletions packages/store/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit de55814

Please sign in to comment.