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

Function createSyncCollection

packages/db/tests/query/includes.test.ts:6299–6331  ·  view source on GitHub ↗
(
      id: string,
      getKey: (item: T) => string | number,
    )

Source from the content-addressed store, hash-verified

6297
6298 describe(`many sibling toArray includes with chained derived collections`, () => {
6299 function createSyncCollection<T extends object>(
6300 id: string,
6301 getKey: (item: T) => string | number,
6302 ) {
6303 let syncBegin: () => void
6304 let syncWrite: (msg: { type: string; value: T }) => void
6305 let syncCommit: () => void
6306
6307 const collection = createCollection<T>({
6308 id,
6309 getKey,
6310 sync: {
6311 sync: (params: any) => {
6312 syncBegin = params.begin
6313 syncWrite = params.write
6314 syncCommit = params.commit
6315 params.markReady()
6316 return () => {}
6317 },
6318 } as SyncConfig<T>,
6319 startSync: true,
6320 gcTime: 0,
6321 })
6322
6323 return {
6324 collection,
6325 insert(value: T) {
6326 syncBegin!()
6327 syncWrite!({ type: `insert`, value })
6328 syncCommit!()
6329 },
6330 }
6331 }
6332
6333 const TIMELINE_KEY = `timeline`
6334

Callers 1

includes.test.tsFile · 0.85

Calls 2

createCollectionFunction · 0.85
markReadyMethod · 0.80

Tested by

no test coverage detected