Skip to content
Myr

fix: clear map creates invalid patches, fixes #663

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 bf90358, 08f72a0 · Browse files · 2 files+27 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+27 added−1 removed

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

2 files+27 added−1 removed

modified:__tests__/map-set.js+22 added
242 unmodified lines
243 })244 expect(map1.has("key")).toBe(true)245 expect(map1.get("key")).toBe(undefined)246 })247248 test("#663 - clear map", () => {249 const map = new Map([250 ["a", "b"],251 ["b", "c"]252 ])253 const result = produceWithPatches(map, draft => {254 draft.clear()255 })256257 expect(result).toEqual([258 new Map(),259 [260 {op: "remove", path: ["a"]},261 {op: "remove", path: ["b"]}262 ],263 [264 {op: "add", path: ["a"], value: "b"},265 {op: "add", path: ["b"], value: "c"}266 ]267 ])268 })269 })270}
modified:src/plugins/mapset.ts+5 added-1 removed
13 unmodified lines
14 loadPlugin,15 markChanged,16 ProxyTypeMap,17 ProxyTypeSet,18 die18 die,19 each20} from "../internal"2122export function enableMapSet() {23 /* istanbul ignore next */
86 unmodified lines
110 assertUnrevoked(state)111 prepareMapCopy(state)112 markChanged(state)113 state.assigned_ = new Map()114 each(state.base_, key => {115 state.assigned_!.set(key, false)116 })117 return state.copy_!.clear()118 }119120 p.forEach = function(
221 unmodified lines