deepSignal values iterator: inherit from prototype

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

Loading…
Cancel
Save