Skip to content
Myr

Cleanup. Don't recurse into frozen data structures

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 9f07525 · Browse files · 3 files+28 added−26 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+28 added−26 removed

  • tests:+18 added−0 removed
  • other:+10 added−26 removed

3 files+28 added−26 removed

modified:__tests__/base.js+18 added
1389 unmodified lines
13901391 expect(world.inc(world).counter.count).toBe(2)1392 })13931394 it("doesnt recurse into frozen structures if external data is frozen", () => {1395 const frozen = {}1396 Object.defineProperty(frozen, "x", {1397 get() {1398 throw "oops"1399 },1400 enumerable: true,1401 configurable: true1402 })1403 Object.freeze(frozen)14041405 expect(() => {1406 produce({}, d => {1407 d.x = frozen1408 })1409 }).not.toThrow()1410 })14111412 // See here: https://github.com/mweststrate/immer/issues/891413 it("supports the spread operator", () => {1414 const base = {foo: {x: 0, y: 0}, bar: [0, 0]}1415 const result = produce(base, draft => {
705 unmodified lines
modified:src/finalize.ts+9 added-26 removed
modified:notes.txt+1 added
17 unmodified lines
18[ ] check todos19[ ] kill marchChangesSweep recursive if possible and no perf impact20[ ] todo try immer perf on really big tree21[ ] optimize each closures away?22[ ] document performance tip: if externally added data is frozen, it doesn't recurse (also update related issue)2324Import size report for immer:25┌───────────────────────┬───────────┬────────────┬───────────┐26│ (index) │ just this │ cumulative │ increment │
52 unmodified lines