Skip to content
Myr

env.ts

This file

Path

src/utils/env.ts

47 lines · 1.6 KiB · TypeScript

Last changed by

feature: Always freeze by default (#702)Michel Weststratebefore adoptiona406c8f

History of this file

Take it

The walk stopped after 200 commits: lines older than 497d1a0 point at it.

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 1–2why, one step back
1// Should be no imports here!
2

fix: Make sure Immer works correctly when Symbol is polyfilled, fixes #577Michel Weststratebefore adoption2b40aec

lines 3–7why, one step back
3// Some things that should be evaluated before all else...
45// We only want to know if non-polyfilled symbols are available6const hasSymbol =7 typeof Symbol !== "undefined" && typeof Symbol("x") === "symbol"

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 8–18why, one step back
8export const hasMap = typeof Map !== "undefined"
9export const hasSet = typeof Set !== "undefined"10export const hasProxies =11 typeof Proxy !== "undefined" &&12 typeof Proxy.revocable !== "undefined" &&13 typeof Reflect !== "undefined"1415/**16 * The sentinel value returned by producers to replace the draft with undefined.17 */18export const NOTHING: Nothing = hasSymbol

fix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e

line 19why, one step back
19 ? Symbol.for("immer-nothing")

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 20–30why, one step back
20 : ({["immer-nothing"]: true} as any)
2122/**23 * To let Immer treat your class instances as plain immutable objects24 * (albeit with a custom prototype), you must define either an instance property25 * or a static property on each of your custom classes.26 *27 * Otherwise, your class instance will never be drafted, which means it won't be28 * safe to mutate in a produce callback.29 */30export const DRAFTABLE: unique symbol = hasSymbol

fix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e

line 31why, one step back
31 ? Symbol.for("immer-draftable")

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 32–34why, one step back
32 : ("__$immer_draftable" as any)
3334export const DRAFT_STATE: unique symbol = hasSymbol

fix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e

line 35why, one step back
35 ? Symbol.for("immer-state")

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 36–37why, one step back
36 : ("__$immer_state" as any)
37

fix: Make sure Immer works correctly when Symbol is polyfilled, fixes #577Michel Weststratebefore adoption2b40aec

lines 38–40why, one step back
38// Even a polyfilled Symbol might provide Symbol.iterator
39export const iteratorSymbol: typeof Symbol.iterator =40 (typeof Symbol != "undefined" && Symbol.iterator) || ("@@iterator" as any)

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 41–47why, one step back
41
42/** Use a class type for `nothing` so its type is unique */43export class Nothing {44 // This lets us do `Exclude<T, Nothing>`45 // @ts-ignore46 private _!: unique symbol47}