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 fileTake it
Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 1–2why, one step back1// Should be no imports here!2fix: Make sure Immer works correctly when Symbol is polyfilled, fixes #577Michel Weststratebefore adoption2b40aec
lines 3–7why, one step back3// 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"Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 8–18why, one step back8export 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 = hasSymbolfix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e
line 19why, one step back19 ? Symbol.for("immer-nothing")Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 20–30why, one step back20 : ({["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 = hasSymbolfix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e
line 31why, one step back31 ? Symbol.for("immer-draftable")Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 32–34why, one step back32 : ("__$immer_draftable" as any)3334export const DRAFT_STATE: unique symbol = hasSymbolfix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e
line 35why, one step back35 ? Symbol.for("immer-state")Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 36–37why, one step back36 : ("__$immer_state" as any)37fix: Make sure Immer works correctly when Symbol is polyfilled, fixes #577Michel Weststratebefore adoption2b40aec
lines 38–40why, one step back38// Even a polyfilled Symbol might provide Symbol.iterator39export const iteratorSymbol: typeof Symbol.iterator =40 (typeof Symbol != "undefined" && Symbol.iterator) || ("@@iterator" as any)Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 41–47why, one step back4142/** 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}