Skip to content
Myr

#627 - new map key with value=undefined

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

authored by Giovanni Visciano · committed by Giovanni Visciano · parent 15e221f · Browse files · 3 files+10 added−16 removed
This commit

State

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

Diff stats

3 files+10 added−16 removed

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

3 files+10 added−16 removed

modified:__tests__/base.js-15 removed
472 unmodified lines
473 expect(nextState.aMap).not.toBe(baseState.aMap)474 expect(nextState.aMap.get("force")).toEqual(true)475 })476477 it("KO ==> new key with value=undefine", () => {478 const nextState = produce(baseState, s => {479 s.aMap.set("new_key", undefined)480 })481 expect(nextState.aMap.has("new_key")).toBe(true)482 })483484 it("OK ==> new key with value=undefine", () => {485 const nextState = produce(baseState, s => {486 s.aMap.set("new_key", 1)487 s.aMap.set("new_key", undefined)488 })489 expect(nextState.aMap.has("new_key")).toBe(true)490 })491 477 it("can assign by a non-primitive key", () => {478 const key = {prop: "val"}479 const value = {id: 1, a: 1}480 const base = new Map([[key, value]])
1972 unmodified lines
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