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

Method toArrayWhenReady

packages/db/src/collection/index.ts:860–868  ·  view source on GitHub ↗

* Gets the current state of the collection as an Array, but only resolves when data is available * Waits for the first sync commit to complete before resolving * * @returns Promise that resolves to an Array containing all items in the collection

()

Source from the content-addressed store, hash-verified

858 * @returns Promise that resolves to an Array containing all items in the collection
859 */
860 toArrayWhenReady(): Promise<Array<WithVirtualProps<TOutput, TKey>>> {
861 // If we already have data or collection is ready, resolve immediately
862 if (this.size > 0 || this.isReady()) {
863 return Promise.resolve(this.toArray)
864 }
865
866 // Use preload to ensure the collection starts loading, then return the array
867 return this.preload().then(() => this.toArray)
868 }
869
870 /**
871 * Returns the current state of the collection as an array of changes

Callers 3

rxdb.test.tsFile · 0.80
useLiveQueryFunction · 0.80

Calls 2

isReadyMethod · 0.95
preloadMethod · 0.95

Tested by

no test coverage detected