MCPcopy Index your code
hub / github.com/TanStack/query / deleteNestedDataByPath

Function deleteNestedDataByPath

packages/query-devtools/src/utils.tsx:249–303  ·  view source on GitHub ↗
(
  oldData: unknown,
  deletePath: Array<string>,
)

Source from the content-addressed store, hash-verified

247 * @returns newData without the deleted items by path
248 */
249export const deleteNestedDataByPath = (
250 oldData: unknown,
251 deletePath: Array<string>,
252): any => {
253 if (oldData instanceof Map) {
254 const newData = new Map(oldData)
255
256 if (deletePath.length === 1) {
257 newData.delete(deletePath[0])
258 return newData
259 }
260
261 const [head, ...tail] = deletePath
262 newData.set(head, deleteNestedDataByPath(newData.get(head), tail))
263 return newData
264 }
265
266 if (oldData instanceof Set) {
267 const setAsArray = deleteNestedDataByPath(Array.from(oldData), deletePath)
268 return new Set(setAsArray)
269 }
270
271 if (Array.isArray(oldData)) {
272 const newData = [...oldData]
273
274 if (deletePath.length === 1) {
275 return newData.filter((_, idx) => idx.toString() !== deletePath[0])
276 }
277
278 const [head, ...tail] = deletePath
279
280 // @ts-expect-error
281 newData[head] = deleteNestedDataByPath(newData[head], tail)
282
283 return newData
284 }
285
286 if (oldData instanceof Object) {
287 const newData = { ...oldData }
288
289 if (deletePath.length === 1) {
290 // @ts-expect-error
291 delete newData[deletePath[0]]
292 return newData
293 }
294
295 const [head, ...tail] = deletePath
296 // @ts-expect-error
297 newData[head] = deleteNestedDataByPath(newData[head], tail)
298
299 return newData
300 }
301
302 return oldData
303}
304
305// Sets up the goober stylesheet
306// Adds a nonce to the style tag if needed

Callers 2

DeleteItemButtonFunction · 0.90
utils.test.tsFile · 0.90

Calls 2

getMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…