Skip to content

Commit d68dd2a

Browse files
authored
Merge branch 'main' into 3850-new-set-methods
2 parents 4acd882 + 5c8066d commit d68dd2a

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

packages/mobx/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# mobx
22

3+
## 6.12.5
4+
5+
### Patch Changes
6+
7+
- [`ba890343`](https://github.com/mobxjs/mobx/commit/ba8903430ce96746db5dcde6b78edeb195ea8018) [#3893](https://github.com/mobxjs/mobx/pull/3893) Thanks [@g6123](https://github.com/g6123)! - Fix ES6 Map/Set checks for cross-window scripts
8+
39
## 6.12.4
410

511
### Patch Changes

packages/mobx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx",
3-
"version": "6.12.4",
3+
"version": "6.12.5",
44
"description": "Simple, scalable state management.",
55
"source": "src/mobx.ts",
66
"main": "dist/index.js",

packages/mobx/src/types/observablemap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
hasListeners,
1717
interceptChange,
1818
isES6Map,
19+
isPlainES6Map,
1920
isPlainObject,
2021
isSpyEnabled,
2122
makeIterable,
@@ -351,7 +352,7 @@ export class ObservableMap<K = any, V = any>
351352
} else if (Array.isArray(other)) {
352353
other.forEach(([key, value]) => this.set(key, value))
353354
} else if (isES6Map(other)) {
354-
if (other.constructor !== Map) {
355+
if (!isPlainES6Map(other)) {
355356
die(19, other)
356357
}
357358
other.forEach((value, key) => this.set(key, value))

packages/mobx/src/utils/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ export function createInstanceofPredicate<T>(
141141
}
142142

143143
export function isES6Map(thing: any): thing is Map<any, any> {
144-
return thing instanceof Map
144+
return thing != null && Object.prototype.toString.call(thing) === "[object Map]"
145+
}
146+
147+
export function isPlainES6Map(thing: Map<any, any>): boolean {
148+
const mapProto = Object.getPrototypeOf(thing)
149+
const objectProto = Object.getPrototypeOf(mapProto)
150+
const nullProto = Object.getPrototypeOf(objectProto)
151+
return nullProto === null
145152
}
146153

147154
export function isES6Set(thing: any): thing is Set<any> {
148-
return thing instanceof Set
155+
return thing != null && Object.prototype.toString.call(thing) === "[object Set]"
149156
}
150157

151158
const hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined"

0 commit comments

Comments
 (0)