current.ts
This file
Path
src/core/current.ts
47 lines · 1.2 KiB · TypeScript
Last changed by
fix: update current and original typings to assert draft value is unwrapped (#1236)Dean Kerrbefore adoptionbf2d154
History of this fileTake it
The walk stopped after 200 commits: lines older than 607b994 point at it.
chore: added unit test for #897Michel Weststratebefore adoption607b994
lines 1–2why, one step back1import {2 die,fix: update current and original typings to assert draft value is unwrapped (#1236)Dean Kerrbefore adoptionbf2d154
line 3why, one step back3 Draft,chore: added unit test for #897Michel Weststratebefore adoption607b994
lines 4–10why, one step back4 isDraft,5 shallowCopy,6 each,7 DRAFT_STATE,8 set,9 ImmerState,10 isDraftable,Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 11why, one step back11 isFrozenchore: added unit test for #897Michel Weststratebefore adoption607b994
lines 12–14why, one step back12} from "../internal"1314/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */fix: update current and original typings to assert draft value is unwrapped (#1236)Dean Kerrbefore adoptionbf2d154
lines 15–16why, one step back15export function current<T>(value: Draft<T>): T16export function current(value: Draft<any>): any {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 17why, one step back17 if (!isDraft(value)) die(10, value)chore: added unit test for #897Michel Weststratebefore adoption607b994
lines 18–21why, one step back18 return currentImpl(value)19}2021function currentImpl(value: any): any {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 22why, one step back22 if (!isDraftable(value) || isFrozen(value)) return valuechore: added unit test for #897Michel Weststratebefore adoption607b994
lines 23–24why, one step back23 const state: ImmerState | undefined = value[DRAFT_STATE]24 let copy: anyfeat: Optimize Immer performance where possible, introduce `setUseStrictIteration` (#1164)Mark Eriksonbefore adoptione1996ce
line 25why, one step back25 let strict = true // Default to strict for compatibilitychore: added unit test for #897Michel Weststratebefore adoption607b994
line 26why, one step back26 if (state) {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 27why, one step back27 if (!state.modified_) return state.base_chore: added unit test for #897Michel Weststratebefore adoption607b994
lines 28–29why, one step back28 // Optimization: avoid generating new drafts during copying29 state.finalized_ = trueMerge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 30why, one step back30 copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)feat: Optimize Immer performance where possible, introduce `setUseStrictIteration` (#1164)Mark Eriksonbefore adoptione1996ce
line 31why, one step back31 strict = state.scope_.immer_.shouldUseStrictIteration()chore: added unit test for #897Michel Weststratebefore adoption607b994
line 32why, one step back32 } else {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 33why, one step back33 copy = shallowCopy(value, true)chore: added unit test for #897Michel Weststratebefore adoption607b994
line 34why, one step back34 }Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 35why, one step back35 // recursefeat: Optimize Immer performance where possible, introduce `setUseStrictIteration` (#1164)Mark Eriksonbefore adoptione1996ce
lines 36–42why, one step back36 each(37 copy,38 (key, childValue) => {39 set(copy, key, currentImpl(childValue))40 },41 strict42 )Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 43–44why, one step back43 if (state) {44 state.finalized_ = falsechore: added unit test for #897Michel Weststratebefore adoption607b994
line 45why, one step back45 }Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 46why, one step back46 return copychore: added unit test for #897Michel Weststratebefore adoption607b994
line 47why, one step back47}