Skip to content
Myr

fix: new map keys were not added if value is undefined

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

authored by Michel Weststrate · committed by GitHub · parents 4057f79, 90978bc · Browse files · 2 files+10 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+10 added−1 removed

  • tests:+9 added−0 removed
  • other:+1 added−1 removed

2 files+10 added−1 removed

modified:__tests__/map-set.js+9 added
233 unmodified lines
234 draftSet.add(3)235 })236 expect(Array.from(set).sort()).toEqual([1, 2, 3])237 })238239 test("#627 - new map key with value=undefined", () => {240 const map = new Map()241 const map1 = produce(map, draft => {242 draft.set("key", undefined)243 })244 expect(map1.has("key")).toBe(true)245 expect(map1.get("key")).toBe(undefined)246 })247 })248}
modified:src/plugins/mapset.ts+1 added-1 removed
78 unmodified lines
7980 p.set = function(key: any, value: any) {81 const state: MapState = this[DRAFT_STATE]82 assertUnrevoked(state)83 if (latest(state).get(key) !== value) {83 if (!latest(state).has(key) || latest(state).get(key) !== value) {84 prepareMapCopy(state)85 markChanged(state)86 state.assigned_!.set(key, true)87 state.copy_!.set(key, value)
250 unmodified lines