Skip to content

Commit

Permalink
Implement Symbol.unscopables on OrderedCollection (#6215)
Browse files Browse the repository at this point in the history
* Implement 'Symbol.unscopables' on 'OrderedCollection'.

* Replace impl. with that of the Array.prototype's unscopable object.

* Add CHANGELOG entry.

* Update package.json change from separate branch.

Accidentally included a package.json change from another branch that has not yet been merged.

* Update link in comment.

* Move CHANGELOG entry from 'Enhancements' to 'Fixed'.

* Update link in comment.
  • Loading branch information
elle-j authored Oct 26, 2023
1 parent 1f5312a commit 23eab15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* None

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None
* `Symbol.unscopables` has been implemented on the base class of `Realm.Results`, `Realm.List`, and `Realm.Set`. ([#6215](https://github.com/realm/realm-js/pull/6215))

### Compatibility
* React Native >= v0.71.4
Expand Down
12 changes: 12 additions & 0 deletions packages/realm/src/OrderedCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ export abstract class OrderedCollection<T = unknown, EntryType extends [unknown,
writable: false,
value: mixedToBinding.bind(undefined, realm.internal),
});
// See https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype-@@unscopables
Object.defineProperty(this, Symbol.unscopables, {
enumerable: false,
configurable: true,
writable: false,
});
return proxied;
}

Expand Down Expand Up @@ -626,6 +632,12 @@ export abstract class OrderedCollection<T = unknown, EntryType extends [unknown,
return this.values();
}

/**
* An Object whose truthy properties are properties that are excluded from the 'with'
* environment bindings of the associated objects.
*/
readonly [Symbol.unscopables] = Array.prototype[Symbol.unscopables];

// Other methods

// TODO: Implement this method
Expand Down

0 comments on commit 23eab15

Please sign in to comment.