Skip to content

Commit

Permalink
Merge branch 'main' into 3850-new-set-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
urugator authored Jul 2, 2024
2 parents 4acd882 + 5c8066d commit d68dd2a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/mobx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# mobx

## 6.12.5

### Patch Changes

- [`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

## 6.12.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx",
"version": "6.12.4",
"version": "6.12.5",
"description": "Simple, scalable state management.",
"source": "src/mobx.ts",
"main": "dist/index.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/mobx/src/types/observablemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
hasListeners,
interceptChange,
isES6Map,
isPlainES6Map,
isPlainObject,
isSpyEnabled,
makeIterable,
Expand Down Expand Up @@ -351,7 +352,7 @@ export class ObservableMap<K = any, V = any>
} else if (Array.isArray(other)) {
other.forEach(([key, value]) => this.set(key, value))
} else if (isES6Map(other)) {
if (other.constructor !== Map) {
if (!isPlainES6Map(other)) {
die(19, other)
}
other.forEach((value, key) => this.set(key, value))
Expand Down
11 changes: 9 additions & 2 deletions packages/mobx/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,18 @@ export function createInstanceofPredicate<T>(
}

export function isES6Map(thing: any): thing is Map<any, any> {
return thing instanceof Map
return thing != null && Object.prototype.toString.call(thing) === "[object Map]"
}

export function isPlainES6Map(thing: Map<any, any>): boolean {
const mapProto = Object.getPrototypeOf(thing)
const objectProto = Object.getPrototypeOf(mapProto)
const nullProto = Object.getPrototypeOf(objectProto)
return nullProto === null
}

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

const hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined"
Expand Down

0 comments on commit d68dd2a

Please sign in to comment.