Skip to content
Myr

docs: more of that

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

authored by Michel Weststrate · committed by Michel Weststrate · parent 85361a7 · Browse files · 2 files+18 added−0 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+18 added−0 removed

  • tests:+10 added−0 removed
  • other:+8 added−0 removed

2 files+18 added−0 removed

modified:__tests__/readme.js+10 added
191 unmodified lines
192test("Producers can update Maps", () => {193 const usersById_v1 = new Map()194195 const usersById_v2 = produce(usersById_v1, draft => {196 // Modifying a map results in a new map197 draft.set("michel", {name: "Michel Weststrate", country: "NL"})198 })199200 const usersById_v3 = produce(usersById_v2, draft => {201 // Making a change deep inside a map, results in a new map as well!202 draft.get("michel").country = "UK"203 })204205 // We got a new map each time!206 expect(usersById_v2).not.toBe(usersById_v1)207 expect(usersById_v3).not.toBe(usersById_v2)208 // With different content obviously209 expect(usersById_v1).toMatchInlineSnapshot(`Map {}`)210 expect(usersById_v2).toMatchInlineSnapshot(`211 Map {212 "michel" => Object {
9 unmodified lines
222 "name": "Michel Weststrate",223 },224 }225 `)226 // The old one was never modified227 expect(usersById_v1.size).toBe(0)228 // And trying to change a Map outside a producers is going to: NO!229 expect(() => usersById_v3.clear()).toThrowErrorMatchingInlineSnapshot(230 `"This object has been frozen and should not be mutated"`231 )232})
modified:docs/complex-objects.md+8 added