Tear down subscriptions and clear state
()
| 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 { |
no test coverage detected