MCPcopy Create free account
hub / github.com/TanStack/db / trackLoadPromise

Method trackLoadPromise

packages/db/src/collection/sync.ts:445–475  ·  view source on GitHub ↗

* Tracks a load promise for isLoadingSubset state. * @internal This is for internal coordination (e.g., live-query glue code), not for general use.

(promise: Promise<void>)

Source from the content-addressed store, hash-verified

443 * @internal This is for internal coordination (e.g., live-query glue code), not for general use.
444 */
445 public trackLoadPromise(promise: Promise<void>): void {
446 const loadingStarting = !this.isLoadingSubset
447 this.pendingLoadSubsetPromises.add(promise)
448
449 if (loadingStarting) {
450 this._events.emit(`loadingSubset:change`, {
451 type: `loadingSubset:change`,
452 collection: this.collection,
453 isLoadingSubset: true,
454 previousIsLoadingSubset: false,
455 loadingSubsetTransition: `start`,
456 })
457 }
458
459 promise.finally(() => {
460 const loadingEnding =
461 this.pendingLoadSubsetPromises.size === 1 &&
462 this.pendingLoadSubsetPromises.has(promise)
463 this.pendingLoadSubsetPromises.delete(promise)
464
465 if (loadingEnding) {
466 this._events.emit(`loadingSubset:change`, {
467 type: `loadingSubset:change`,
468 collection: this.collection,
469 isLoadingSubset: false,
470 previousIsLoadingSubset: true,
471 loadingSubsetTransition: `end`,
472 })
473 }
474 })
475 }
476
477 /**
478 * Requests the sync layer to load more data.

Callers 5

loadSubsetMethod · 0.95
trackLoadResultMethod · 0.80
ensureLoadingPromiseMethod · 0.80

Calls 4

emitMethod · 0.80
addMethod · 0.45
hasMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected