From 0df18c651f2311e2e26f3e6c8535a9e40b71502f Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Fri, 24 Jan 2025 16:48:38 -0700 Subject: [PATCH] fix patching arrays... again --- client/lib/json-patch-lib.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/client/lib/json-patch-lib.ts b/client/lib/json-patch-lib.ts index 4c0f3db..dfdcc31 100644 --- a/client/lib/json-patch-lib.ts +++ b/client/lib/json-patch-lib.ts @@ -117,16 +117,9 @@ function recursiveApplyArray( const result = [...data] as T // add/remove is only handled differently if this is the last segment in the path - if (path.length === 1) { - if (op === PatchOp.ADD) result.splice(index, 0, value) - else if (op === PatchOp.REMOVE) result.splice(index, 1) - } else { - result.splice( - index, - 1, - recursiveApply(data[index], path.slice(1), op, value), - ) - } + if (path.length === 1 && op === PatchOp.ADD) result.splice(index, 0, value) + else if (path.length === 1 && op === PatchOp.REMOVE) result.splice(index, 1) + else result[index] = recursiveApply(data[index], path.slice(1), op, value) return result }