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