Skip to content
Myr

fix(es5): throw if a modified child draft is returned

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

To be more consistent with the native Proxy implementation.

authored by aleclarson · committed by aleclarson · parent 271cd1b · Browse files · 2 files+16 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+16 added−1 removed

  • tests:+12 added−1 removed
  • other:+4 added−0 removed

2 files+16 added−1 removed

modified:__tests__/base.js+12 added-1 removed
792 unmodified lines
793 expect(res).not.toBe(base)794 expect(res).toEqual({x: 4})795 })796797 it("can return a child draft", () => {797 it("can return an unmodified child draft", () => {798 const base = {a: {}}799 const res = produce(base, d => {800 return d.a801 })802 expect(res).toBe(base.a)803 })804805 // TODO: Avoid throwing if only the child draft was modified.806 it("cannot return a modified child draft", () => {807 const base = {a: {}}808 expect(() => {809 produce(base, d => {810 d.a.b = 1811 return d.a812 })813 }).toThrow(/^An immer producer returned/)814 })815816 it("can return a frozen object", () => {817 const res = deepFreeze([{x: 3}])818 expect(produce({}, () => res)).toBe(res)819 })
343 unmodified lines
modified:src/es5.js+4 added
24 unmodified lines
25 if (needPatches) markChangesRecursively(baseDraft)26 // This is faster when we don't care about which attributes changed.27 markChangesSweep(scope)28 }29 // When a child draft is returned, look for changes.30 else if (isDraft(result) && result[DRAFT_STATE].scope === scope) {31 markChangesSweep(scope.drafts)32 }33}3435export function createDraft(base, parent) {36 const isArray = Array.isArray(base)
202 unmodified lines