( target: T, path: Array<string>, )
| 2271 | } |
| 2272 | |
| 2273 | function 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 | |
| 2299 | function accumulateChanges<T>( |
| 2300 | acc: Map<unknown, Changes<T>>, |
no outgoing calls
no test coverage detected