source: frontend/node_modules/immer/src/utils/env.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.6 KB
Line 
1// Should be no imports here!
2
3// Some things that should be evaluated before all else...
4
5// We only want to know if non-polyfilled symbols are available
6const hasSymbol =
7 typeof Symbol !== "undefined" && typeof Symbol("x") === "symbol"
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"
14
15/**
16 * The sentinel value returned by producers to replace the draft with undefined.
17 */
18export const NOTHING: Nothing = hasSymbol
19 ? Symbol.for("immer-nothing")
20 : ({["immer-nothing"]: true} as any)
21
22/**
23 * To let Immer treat your class instances as plain immutable objects
24 * (albeit with a custom prototype), you must define either an instance property
25 * 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 be
28 * safe to mutate in a produce callback.
29 */
30export const DRAFTABLE: unique symbol = hasSymbol
31 ? Symbol.for("immer-draftable")
32 : ("__$immer_draftable" as any)
33
34export const DRAFT_STATE: unique symbol = hasSymbol
35 ? Symbol.for("immer-state")
36 : ("__$immer_state" as any)
37
38// Even a polyfilled Symbol might provide Symbol.iterator
39export const iteratorSymbol: typeof Symbol.iterator =
40 (typeof Symbol != "undefined" && Symbol.iterator) || ("@@iterator" as any)
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-ignore
46 private _!: unique symbol
47}
Note: See TracBrowser for help on using the repository browser.