Skip to content

Commit 4c07773

Browse files
authored
Fix(mobx): Safer method to consume Iterator.prototype (#3943)
* Fix browser incompatability issue introduced in mobx 6.13.4 * No need for bracket notiation * Proper fallback
1 parent 7f10f7a commit 4c07773

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.changeset/five-news-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx": patch
3+
---
4+
5+
Fix browser compatability issue introduced in 6.13.4 release
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import { getGlobal } from "../internal"
2+
3+
// safely get iterator prototype if available
4+
const maybeIteratorPrototype = getGlobal().Iterator?.prototype || {}
5+
16
export function makeIterable<T, TReturn = unknown>(
27
iterator: Iterator<T>
38
): IteratorObject<T, TReturn> {
4-
return Object.assign(Object.create(Iterator.prototype), iterator)
9+
iterator[Symbol.iterator] = getSelf
10+
return Object.assign(Object.create(maybeIteratorPrototype), iterator)
11+
}
12+
13+
function getSelf() {
14+
return this
515
}

0 commit comments

Comments
 (0)