mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 02:11:54 +00:00
much more efficient (#46)
* much more efficient * update children too * better compare
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user