Skip to content
Myr

fix: immerjs#876 Ensure empty patch set for atomic set+delete on Map (#878)

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

authored by Julian Scheid · committed by GitHub · parent 8507692 · Browse files · 2 files+26 added−1 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+26 added−1 removed

  • tests:+21 added−0 removed
  • other:+5 added−1 removed

2 files+26 added−1 removed

modified:__tests__/patch.js+21 added
1317 unmodified lines
1318 expect(patches).toEqual([{op: "replace", path: [], value: undefined}])13191320 expect(applyPatches({}, patches)).toEqual(undefined)1321})13221323test("#876 Ensure empty patch set for atomic set+delete on Map", () => {1324 {1325 const [newState, patches] = produceWithPatches(1326 new Map([["foo", "baz"]]),1327 draft => {1328 draft.set("foo", "bar")1329 draft.delete("foo")1330 }1331 )1332 expect(patches).toEqual([{op: "remove", path: ["foo"]}])1333 }13341335 {1336 const [newState, patches] = produceWithPatches(new Map(), draft => {1337 draft.set("foo", "bar")1338 draft.delete("foo")1339 })1340 expect(patches).toEqual([])1341 }1342})
modified:src/plugins/mapset.ts+5 added-1 removed
97 unmodified lines
98 const state: MapState = this[DRAFT_STATE]99 assertUnrevoked(state)100 prepareMapCopy(state)101 markChanged(state)102 if (state.base_.has(key)) {102 state.assigned_!.set(key, false)103 state.assigned_!.set(key, false)104 } else {105 state.assigned_!.delete(key)106 }107 state.copy_!.delete(key)108 return true109 }110
238 unmodified lines