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

Method addSubscriber

packages/db/src/collection/changes.ts:182–199  ·  view source on GitHub ↗

* Increment the active subscribers count and start sync if needed

()

Source from the content-addressed store, hash-verified

180 * Increment the active subscribers count and start sync if needed
181 */
182 private addSubscriber(): void {
183 const previousSubscriberCount = this.activeSubscribersCount
184 this.activeSubscribersCount++
185 this.lifecycle.cancelGCTimer()
186
187 // Start sync if collection was cleaned up
188 if (
189 this.lifecycle.status === `cleaned-up` ||
190 this.lifecycle.status === `idle`
191 ) {
192 this.sync.startSync()
193 }
194
195 this.events.emitSubscribersChange(
196 this.activeSubscribersCount,
197 previousSubscriberCount,
198 )
199 }
200
201 /**
202 * Decrement the active subscribers count and start GC timer if needed

Callers 1

subscribeChangesMethod · 0.95

Calls 3

cancelGCTimerMethod · 0.80
startSyncMethod · 0.80
emitSubscribersChangeMethod · 0.80

Tested by

no test coverage detected