env.ts
This file
Path
src/utils/env.ts
51 lines · 1.7 KiB · TypeScript
Last changed by
fix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e
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–22why, 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/* istanbul ignore next */16function mini() {}17export const isMinified = mini.name !== "mini"1819/**20 * The sentinel value returned by producers to replace the draft with undefined.21 */22export const NOTHING: Nothing = hasSymbolfix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e
line 23why, one step back23 ? Symbol.for("immer-nothing")Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 24–34why, one step back24 : ({["immer-nothing"]: true} as any)2526/**27 * To let Immer treat your class instances as plain immutable objects28 * (albeit with a custom prototype), you must define either an instance property29 * or a static property on each of your custom classes.30 *31 * Otherwise, your class instance will never be drafted, which means it won't be32 * safe to mutate in a produce callback.33 */34export const DRAFTABLE: unique symbol = hasSymbolfix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e
line 35why, one step back35 ? Symbol.for("immer-draftable")Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 36–38why, one step back36 : ("__$immer_draftable" as any)3738export const DRAFT_STATE: unique symbol = hasSymbolfix: made NOTHING and IMMERABLE shared symbols. Fixes #632Michel Weststratebefore adoptionb1c6a8e
line 39why, one step back39 ? Symbol.for("immer-state")Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 40–41why, one step back40 : ("__$immer_state" as any)41fix: Make sure Immer works correctly when Symbol is polyfilled, fixes #577Michel Weststratebefore adoption2b40aec
lines 42–44why, one step back42// Even a polyfilled Symbol might provide Symbol.iterator43export const iteratorSymbol: typeof Symbol.iterator =44 (typeof Symbol != "undefined" && Symbol.iterator) || ("@@iterator" as any)Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 45–51why, one step back4546/** Use a class type for `nothing` so its type is unique */47export class Nothing {48 // This lets us do `Exclude<T, Nothing>`49 // @ts-ignore50 private _!: unique symbol51}