Skip to content

Commit

Permalink
fix: Make sure Immer works correctly when Symbol is polyfilled, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed May 23, 2020
1 parent 169db77 commit 2b40aec
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/utils/env.ts
@@ -1,7 +1,10 @@
// Should be no imports here!

// SOme things that should be evaluated before all else...
const hasSymbol = typeof Symbol !== "undefined"
// Some things that should be evaluated before all else...

// We only want to know if non-polyfilled symbols are available
const hasSymbol =
typeof Symbol !== "undefined" && typeof Symbol("x") === "symbol"
export const hasMap = typeof Map !== "undefined"
export const hasSet = typeof Set !== "undefined"
export const hasProxies =
Expand Down Expand Up @@ -36,9 +39,9 @@ export const DRAFT_STATE: unique symbol = hasSymbol
? Symbol("immer-state")
: ("__$immer_state" as any)

export const iteratorSymbol: typeof Symbol.iterator = hasSymbol
? Symbol.iterator
: ("@@iterator" as any)
// Even a polyfilled Symbol might provide Symbol.iterator
export const iteratorSymbol: typeof Symbol.iterator =
(typeof Symbol != "undefined" && Symbol.iterator) || ("@@iterator" as any)

/** Use a class type for `nothing` so its type is unique */
export class Nothing {
Expand Down

0 comments on commit 2b40aec

Please sign in to comment.