Skip to content

Commit

Permalink
Fix(mobx): Safer method to consume Iterator.prototype (#3943)
Browse files Browse the repository at this point in the history
* Fix browser incompatability issue introduced in mobx 6.13.4

* No need for bracket notiation

* Proper fallback
  • Loading branch information
tonyraoul authored Oct 16, 2024
1 parent 7f10f7a commit 4c07773
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/five-news-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx": patch
---

Fix browser compatability issue introduced in 6.13.4 release
12 changes: 11 additions & 1 deletion packages/mobx/src/utils/iterable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { getGlobal } from "../internal"

// safely get iterator prototype if available
const maybeIteratorPrototype = getGlobal().Iterator?.prototype || {}

export function makeIterable<T, TReturn = unknown>(
iterator: Iterator<T>
): IteratorObject<T, TReturn> {
return Object.assign(Object.create(Iterator.prototype), iterator)
iterator[Symbol.iterator] = getSelf
return Object.assign(Object.create(maybeIteratorPrototype), iterator)
}

function getSelf() {
return this
}

0 comments on commit 4c07773

Please sign in to comment.