much more efficient (#46)

* much more efficient

* update children too

* better compare
This commit is contained in:
Matt Hill
2022-09-14 11:21:00 -06:00
committed by GitHub
parent 74c01eb5db
commit 20beb61baa
2 changed files with 46 additions and 35 deletions

View File

@@ -43,6 +43,10 @@ export function applyOperation<T>(
doc.data = recursiveApply(doc.data, jsonPathToKeyArray(path), op, value)
}
export function jsonPathToKeyArray(path: string): string[] {
return path.split('/').slice(1)
}
function recursiveApply<T extends Record<string, any> | any[]>(
data: T,
path: readonly string[],
@@ -105,7 +109,3 @@ function recursiveApplyArray<T extends any[]>(
function isObject(val: any): val is Record<string, unknown> {
return typeof val === 'object' && val !== null && !Array.isArray(val)
}
function jsonPathToKeyArray(path: string): string[] {
return path.split('/').slice(1)
}