deepSignal values iterator: inherit from prototype

feat/orm-diffs
Laurin Weger 3 days ago
parent 29905f5ab8
commit cce7dbfbe9
No known key found for this signature in database
GPG Key ID: 9B372BB0B792770F
  1. 13
      sdk/js/alien-deepsignals/src/deepSignal.ts

@ -678,9 +678,9 @@ function getFromSet(
const makeIterator = (pair: boolean) => {
return function thisIter(this: any) {
const iterable = raw.values();
return {
[Symbol.iterator]() {
return {
// Create an Iterator that inherits Iterator.prototype methods (map, filter, etc.)
// Wrap the iterator to proxy entries on-demand
const wrappedIterator = {
next() {
const n = iterable.next();
if (n.done) return n;
@ -691,8 +691,11 @@ function getFromSet(
};
},
};
},
} as Iterable<any>;
// Set the prototype to Iterator.prototype if available (ES2023+ Iterator Helpers)
if (typeof Iterator !== "undefined" && Iterator.prototype) {
Object.setPrototypeOf(wrappedIterator, Iterator.prototype);
}
return wrappedIterator;
};
};
if (key === "values" || key === "keys") return makeIterator(false);

Loading…
Cancel
Save