Skip to content
Myr

invalidate the proxy of the base state after immer function executes

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

Fixes #10

authored by Oussama Ben Brahim · committed by Oussama Ben Brahim · parent 101aac2 · Browse files · 2 files+57 added−9 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+57 added−9 removed

  • tests:+24 added−1 removed
  • other:+33 added−8 removed

2 files+57 added−9 removed

modified:__tests__/base.js+24 added-1 removed
173 unmodified lines
174 const nextState = immer(baseState, s => {175 s.aProp = undefined176 })177 expect(nextState).not.toBe(baseState)178 expect(baseState.aProp).toBe('hi')178 expect(baseState.aProp).toBe("hi")179 expect(nextState.aProp).toBe(undefined)180 })181182 it("should revoke the proxy of the baseState after immer function is executed", () => {183 let proxy184 const nextState = immer(baseState, s => {185 proxy = s186 s.aProp = "hello"187 })188 expect(nextState).not.toBe(baseState)189 expect(baseState.aProp).toBe("hi")190 expect(nextState.aProp).toBe("hello")191192 expect(() => {193 proxy.aProp = "Hallo"194 }).toThrowError(/^Cannot perform.*on a proxy that has been revoked/)195 expect(() => {196 const aProp = proxy.aProp197 }).toThrowError(/^Cannot perform.*on a proxy that has been revoked/) 198199 expect(nextState).not.toBe(baseState)200 expect(baseState.aProp).toBe("hi")201 expect(nextState.aProp).toBe("hello")202203 })204 205 afterEach(() => {206 expect(baseState).toBe(origBaseState)207 expect(baseState).toEqual(createBaseState())208 })
48 unmodified lines
modified:immer.js+33 added-8 removed