Skip to content
Myr

fix: special case NaN in setter (#912)

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

* fix: special case NaN in setter * fix: naN special case

authored by Ray · committed by GitHub · parent 8aac6ca · Browse files · 2 files+21 added−4 removed
This commit

State

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

Trailers

  • Co-authored-by: zhangpeifeng <zhangpeifeng.zpf@alibaba-inc.com>

Diff stats

2 files+21 added−4 removed

  • tests:+17 added−0 removed
  • other:+4 added−4 removed

2 files+21 added−4 removed

modified:__tests__/base.js+17 added
1280 unmodified lines
1281 expect(nextState).not.toBe(baseState)1282 expect(nextState).not.toEqual(baseState)1283 })12841285 it("should handle equality correctly - 3", () => {1286 const baseState = {1287 x: "s1",1288 y: 1,1289 z: NaN1290 }1291 const nextState = produce(baseState, draft => {1292 draft.x = "s2"1293 draft.y = 11294 draft.z = NaN1295 expect(draft[DRAFT_STATE].assigned_.x).toBe(true)1296 expect(draft[DRAFT_STATE].assigned_.y).toBe(undefined)1297 expect(draft[DRAFT_STATE].assigned_.z).toBe(undefined)1298 })1299 expect(nextState.x).toBe("s2")1300 })13011302 // AKA: recursive produce calls1303 describe("nested producers", () => {1304 describe("when base state is not a draft", () => {1305 // This test ensures the global state used to manage proxies is
1181 unmodified lines
modified:src/core/proxy.ts+4 added-4 removed
156 unmodified lines
157 markChanged(state)158 }159160 if (161 state.copy_![prop] === value &&161 (state.copy_![prop] === value &&162 // special case: handle new props with value 'undefined'163 (value !== undefined || prop in state.copy_)) ||164 // special case: NaN163 typeof value !== "number" &&164 // special case: handle new props with value 'undefined'165 (value !== undefined || prop in state.copy_)165 (Number.isNaN(value) && Number.isNaN(state.copy_![prop]))166 )167 return true168169 // @ts-ignore
111 unmodified lines