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

Function clonePathForUpdate

packages/db/src/query/live/collection-config-builder.ts:2273–2297  ·  view source on GitHub ↗
(
  target: T,
  path: Array<string>,
)

Source from the content-addressed store, hash-verified

2271}
2272
2273function clonePathForUpdate<T extends Record<string, any>>(
2274 target: T,
2275 path: Array<string>,
2276): T {
2277 const root = { ...target }
2278 let sourceCursor: any = target
2279 let cloneCursor: any = root
2280
2281 for (let i = 0; i < path.length - 1; i++) {
2282 const segment = path[i]!
2283 const sourceValue = sourceCursor?.[segment]
2284 if (sourceValue == null || typeof sourceValue !== `object`) {
2285 return root
2286 }
2287
2288 const clonedValue = Array.isArray(sourceValue)
2289 ? [...sourceValue]
2290 : { ...sourceValue }
2291 cloneCursor[segment] = clonedValue
2292 sourceCursor = sourceValue
2293 cloneCursor = clonedValue
2294 }
2295
2296 return root
2297}
2298
2299function accumulateChanges<T>(
2300 acc: Map<unknown, Changes<T>>,

Callers 1

cloneForIncludesUpdateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected