Skip to content
Myr

Return undefined for unwrapped values / update tests

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

authored by RichieAHB · committed by RichieAHB · parent 590025f · Browse files · 3 files+37 added−7 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+37 added−7 removed

  • tests:+32 added−5 removed
  • other:+5 added−2 removed

3 files+37 added−7 removed

modified:__tests__/original.js+32 added-5 removed
modified:src/common.js+4 added-1 removed
55 unmodified lines
56 return value57}5859export function original(value) {60 return value && value[PROXY_STATE] ? value[PROXY_STATE].base : value60 if (value && value[PROXY_STATE]) {61 return value[PROXY_STATE].base62 }63 // otherwise return undefined64}6566const assign =67 Object.assign ||
108 unmodified lines
modified:readme.md+1 added-1 removed
351 unmodified lines
352```353354## Extracting the original object from a proxied instance355356Immer exposes a named export `original` that will get the original object from the proxied instance inside `produce`. A good example of when this can be useful is when searching for nodes in a tree-like state using strict equality.356Immer exposes a named export `original` that will get the original object from the proxied instance inside `produce` (or return `undefined` for unproxied values). A good example of when this can be useful is when searching for nodes in a tree-like state using strict equality.357358```js359const baseState = { users: [{ name: "Richie" }] };360const nextState = produce(baseState, draftState => {
247 unmodified lines