Skip to content
Myr

fix: #807 new undefined properties should end up in result object

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 5412c9f · Browse files · 2 files+20 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+20 added−1 removed

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

2 files+20 added−1 removed

modified:__tests__/regressions.js+12 added
237 unmodified lines
238 expect(next).toEqual({239 bar: {x: 3}240 })241 })242243 test("#807 new undefined member not stored", () => {244 const state = {}245 const newState = produce(state, draft => {246 draft.baz = undefined247 })248 expect(state).not.toBe(newState)249 expect(Object.hasOwnProperty.call(newState, "baz")).toBe(true)250 expect(newState).toEqual({251 baz: undefined252 })253 })254 })255}
modified:src/core/proxy.ts+8 added-1 removed
155 unmodified lines
156 prepareCopy(state)157 markChanged(state)158 }159160 if (state.copy_![prop] === value && typeof value !== "number") return true160 if (161 state.copy_![prop] === value &&162 // special case: NaN163 typeof value !== "number" &&164 // special case: handle new props with value 'undefined'165 (value !== undefined || prop in state.copy_)166 )167 return true168169 // @ts-ignore170 state.copy_![prop] = value171 state.assigned_[prop] = true
108 unmodified lines