Skip to content
Myr

feat: Always use remove command in generateArrayPatches()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #208

authored by jsdevtom · committed by jsdevtom · parent a16deda · Browse files · 2 files+30 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+30 added−19 removed

  • tests:+28 added−5 removed
  • other:+2 added−14 removed

2 files+30 added−19 removed

modified:__tests__/patch.js+28 added-5 removed
247 unmodified lines
248 d => {249 d.x[0] = 4250 d.x.length = 2251 },252 [{op: "replace", path: ["x", 0], value: 4}, {op: "remove", path: ["x", 2]}],253 [253 {op: "replace", path: ["x", 0], value: 4},254 {op: "replace", path: ["x", "length"], value: 2}254 {op: "replace", path: ["x", 0], value: 1},255 {op: "add", path: ["x", 2], value: 3}256 ]257 )258})259
30 unmodified lines
290 {x: [1, 2, 3]},291 d => {292 d.x.length -= 2293 },293 [{op: "replace", path: ["x", "length"], value: 1}],294 [{op: "remove", path: ["x", 2]}, {op: "remove", path: ["x", 1]}],295 [296 {op: "add", path: ["x", 1], value: 2},297 {op: "add", path: ["x", 2], value: 3}298 ]
6 unmodified lines
305 d => {306 d.x.pop()307 d.x.pop()308 },308 [{op: "replace", path: ["x", "length"], value: 1}]309 [{op: "remove", path: ["x", 2]}, {op: "remove", path: ["x", 1]}]310 )311})312313describe("arrays - push multiple", () => {
5 unmodified lines
319 [320 {op: "add", path: ["x", 3], value: 4},321 {op: "add", path: ["x", 4], value: 5}322 ],322 [{op: "replace", path: ["x", "length"], value: 3}]323 [{op: "remove", path: ["x", 4]}, {op: "remove", path: ["x", 3]}]324 )325})326327describe("arrays - splice (expand)", () => {
33 unmodified lines
361 ]362 )363})364365describe("arrays - splice should should result in remove op.", () => {366 runPatchTest(367 [1, 2],368 d => {369 d.splice(1, 1)370 },371 [{op: "remove", path: [1]}],372 [{op: "add", path: [1], value: 2}]373 )374})375376describe("arrays - NESTED splice should should result in remove op.", () => {377 runPatchTest(378 {a: {b: {c: [1, 2]}}},379 d => {380 d.a.b.c.splice(1, 1)381 },382 [{op: "remove", path: ["a", "b", "c", 1]}],383 [{op: "add", path: ["a", "b", "c", 1], value: 2}]384 )385})386387describe("simple replacement", () => {388 runPatchTest({x: 3}, _d => 4, [{op: "replace", path: [], value: 4}])389})390
164 unmodified lines
modified:src/patches.js+2 added-14 removed