MCPcopy Index your code
hub / github.com/TanStack/db / dispose

Method dispose

packages/db/src/query/effect.ts:959–993  ·  view source on GitHub ↗

Tear down subscriptions and clear state

()

Source from the content-addressed store, hash-verified

957
958 /** Tear down subscriptions and clear state */
959 dispose(): void {
960 if (this.disposed) return
961 this.disposed = true
962 this.subscribedToAllCollections = false
963
964 // Immediately unsubscribe from sources and clear cheap state
965 this.unsubscribeCallbacks.forEach((fn) => fn())
966 this.unsubscribeCallbacks.clear()
967 this.sentToD2KeysByAlias.clear()
968 this.pendingChanges.clear()
969 this.lazySources.clear()
970 this.builderDependencies.clear()
971 this.biggestSentValue.clear()
972 this.lastLoadRequestKey.clear()
973 this.pendingOrderedLoadPromise = undefined
974
975 // Clear mutable objects
976 for (const key of Object.keys(this.lazySourcesCallbacks)) {
977 delete this.lazySourcesCallbacks[key]
978 }
979 for (const key of Object.keys(this.aliasDependencies)) {
980 delete this.aliasDependencies[key]
981 }
982 for (const key of Object.keys(this.optimizableOrderByCollections)) {
983 delete this.optimizableOrderByCollections[key]
984 }
985
986 // If the graph is currently running, defer clearing graph/inputs/pipeline
987 // until runGraph() completes — otherwise we'd null references mid-loop.
988 if (this.isGraphRunning) {
989 this.deferredCleanup = true
990 } else {
991 this.finalCleanup()
992 }
993 }
994
995 /** Clear graph references — called after graph run completes or immediately from dispose */
996 private finalCleanup(): void {

Callers 3

useLiveQueryEffectFunction · 0.45
disposeFunction · 0.45
effect.test.tsFile · 0.45

Calls 5

finalCleanupMethod · 0.95
fnFunction · 0.85
forEachMethod · 0.45
clearMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected