Skip to content
Myr

env.ts

This file

Path

src/utils/env.ts

48 lines · 1.5 KiB · TypeScript

Last changed by

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

History of this file

Take it

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 1–48why, one step back
1// Should be no imports here!
23// SOme things that should be evaluated before all else...4const hasSymbol = typeof Symbol !== "undefined"5export const hasMap = typeof Map !== "undefined"6export const hasSet = typeof Set !== "undefined"7export const hasProxies =8 typeof Proxy !== "undefined" &&9 typeof Proxy.revocable !== "undefined" &&10 typeof Reflect !== "undefined"1112/* istanbul ignore next */13function mini() {}14export const isMinified = mini.name !== "mini"1516/**17 * The sentinel value returned by producers to replace the draft with undefined.18 */19export const NOTHING: Nothing = hasSymbol20 ? Symbol("immer-nothing")21 : ({["immer-nothing"]: true} as any)2223/**24 * To let Immer treat your class instances as plain immutable objects25 * (albeit with a custom prototype), you must define either an instance property26 * or a static property on each of your custom classes.27 *28 * Otherwise, your class instance will never be drafted, which means it won't be29 * safe to mutate in a produce callback.30 */31export const DRAFTABLE: unique symbol = hasSymbol32 ? Symbol("immer-draftable")33 : ("__$immer_draftable" as any)3435export const DRAFT_STATE: unique symbol = hasSymbol36 ? Symbol("immer-state")37 : ("__$immer_state" as any)3839export const iteratorSymbol: typeof Symbol.iterator = hasSymbol40 ? Symbol.iterator41 : ("@@iterator" as any)4243/** Use a class type for `nothing` so its type is unique */44export class Nothing {45 // This lets us do `Exclude<T, Nothing>`46 // @ts-ignore47 private _!: unique symbol48}