mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 02:11:54 +00:00
fix patching of arrays
This commit is contained in:
@@ -115,14 +115,17 @@ function recursiveApplyArray<T extends any[]>(
|
|||||||
): T {
|
): T {
|
||||||
const index = parseInt(path[0])
|
const index = parseInt(path[0])
|
||||||
|
|
||||||
const updated = recursiveApply(data[index], path.slice(1), op, value)
|
|
||||||
const result = [...data] as T
|
const result = [...data] as T
|
||||||
if (op === PatchOp.ADD) {
|
// add/remove is only handled differently if this is the last segment in the path
|
||||||
result.splice(index, 0, updated)
|
if (path.length === 1) {
|
||||||
} else if (op === PatchOp.REPLACE) {
|
if (op === PatchOp.ADD) result.splice(index, 0, value)
|
||||||
result.splice(index, 1, updated)
|
else if (op === PatchOp.REMOVE) result.splice(index, 1)
|
||||||
} else {
|
} else {
|
||||||
result.splice(index, 1)
|
result.splice(
|
||||||
|
index,
|
||||||
|
1,
|
||||||
|
recursiveApply(data[index], path.slice(1), op, value),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user