Skip to content
Myr

fix: Map.prototype.set should return a draft

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

authored by Andrey Goncharov · committed by Alec Larson · parent 5c728a4 · Browse files · 3 files+23 added−3 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+23 added−3 removed

  • tests:+21 added−2 removed
  • other:+2 added−1 removed

3 files+23 added−3 removed

modified:__tests__/base.js+4 added-2 removed
1"use strict"2import {Immer, nothing, original, isDraft, immerable} from "../src/index"3import {each, shallowCopy, isEnumerable} from "../src/common"3import {each, shallowCopy, isEnumerable, DRAFT_STATE} from "../src/common"4import deepFreeze from "deep-freeze"5import cloneDeep from "lodash.clonedeep"6import * as lodash from "lodash"7
420 unmodified lines
428 })429430 it("can assign by key", () => {431 const nextState = produce(baseState, s => {432 // Map.prototype.set should return the Map itself432 s.aMap.set("force", true)433 const res = s.aMap.set("force", true)434 expect(res).toBe(s.aMap[DRAFT_STATE].draft)435 })436 expect(nextState).not.toBe(baseState)437 expect(nextState.aMap).not.toBe(baseState.aMap)438 expect(nextState.aMap.get("force")).toEqual(true)
1042 unmodified lines
modified:__tests__/patch.js+17 added
138 unmodified lines
139 true140 )141})142143describe("simple assignment - 6", () => {144 runPatchTest(145 new Map([["x", 1]]),146 d => {147 // Map.prototype.set should return the Map itself148 const res = d.set("x", 2)149 res.set("y", 3)150 },151 [152 {op: "replace", path: ["x"], value: 2},153 {op: "add", path: ["y"], value: 3}154 ],155 [{op: "replace", path: ["x"], value: 1}, {op: "remove", path: ["y"]}],156 true157 )158})159160describe("delete 1", () => {161 runPatchTest(162 {x: {y: 4}},163 d => {
422 unmodified lines
modified:src/proxy.js+2 added-1 removed
189 unmodified lines
190 },191 set: state => (key, value) => {192 markChanged(state)193 state.assigned[key] = true194 return state.copy.set(key, value)194 state.copy.set(key, value)195 return state.draft196 },197 delete: state => key => {198 markChanged(state)199 state.assigned[key] = false
100 unmodified lines