Skip to content

Commit

Permalink
fix ie11
Browse files Browse the repository at this point in the history
  • Loading branch information
runnez committed Oct 25, 2019
1 parent ff25a83 commit ffd8769
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ typings/

.idea
dist/
website/build
website/build
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Test in Browser</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/index.min.js"></script>
<script src="./dist/immer.umd.js"></script>
</head>
<body>
<script>
try {
const result = immer.produce(new Map([[1, 2]]), function(draft) {
draft.set(1, 3)
})

console.log(result)
} catch (err) {
alert(err)
}
</script>
</body>
</html>
6 changes: 4 additions & 2 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ export function is(x, y) {
}
}

const hasMap = typeof Map !== "undefined"
export const hasSymbol = typeof Symbol !== "undefined"

export const hasMap = typeof Map !== "undefined"

export function isMap(target) {
return hasMap && target instanceof Map
}

const hasSet = typeof Set !== "undefined"
export const hasSet = typeof Set !== "undefined"

export function isSet(target) {
return hasSet && target instanceof Set
Expand Down
5 changes: 3 additions & 2 deletions src/es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isEnumerable,
isMap,
isSet,
hasSymbol,
shallowCopy,
DRAFT_STATE,
iterateMapValues,
Expand Down Expand Up @@ -160,7 +161,7 @@ function proxyProperty(draft, prop, enumerable) {
function proxyMap(target) {
Object.defineProperties(target, mapTraps)

if (typeof Symbol !== undefined) {
if (hasSymbol) {
Object.defineProperty(
target,
Symbol.iterator,
Expand Down Expand Up @@ -227,7 +228,7 @@ const mapTraps = finalizeTraps({
function proxySet(target) {
Object.defineProperties(target, setTraps)

if (typeof Symbol !== undefined) {
if (hasSymbol) {
Object.defineProperty(
target,
Symbol.iterator,
Expand Down
2 changes: 1 addition & 1 deletion src/immer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Immer {
if (hasError) scope.revoke()
else scope.leave()
}
if (result instanceof Promise) {
if (typeof Promise !== "undefined" && result instanceof Promise) {
return result.then(
result => {
scope.usePatches(patchListener)
Expand Down
5 changes: 3 additions & 2 deletions src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isDraft,
isMap,
isSet,
hasSymbol,
shallowCopy,
makeIterable,
DRAFT_STATE,
Expand Down Expand Up @@ -258,7 +259,7 @@ const mapTraps = makeTrapsForGetters({
keys: state => () => latest(state).keys(),
values: iterateMapValues,
entries: iterateMapValues,
[Symbol.iterator]: iterateMapValues
[hasSymbol && Symbol.iterator]: iterateMapValues
})

const iterateSetValues = makeIterateSetValues(createProxy)
Expand Down Expand Up @@ -296,7 +297,7 @@ const setTraps = makeTrapsForGetters({
keys: iterateSetValues,
values: iterateSetValues,
entries: iterateSetValues,
[Symbol.iterator]: iterateSetValues
[hasSymbol && Symbol.iterator]: iterateSetValues
})

/**
Expand Down

0 comments on commit ffd8769

Please sign in to comment.