avoid generator functions

pull/10803/head
Rich Harris 2 years ago
parent 5c8b47ddfb
commit a5a4dbf097

@ -2,6 +2,7 @@ import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { UNINITIALIZED } from '../internal/client/constants.js';
import { map } from './utils.js';
/**
* @template K
@ -133,20 +134,17 @@ export class ReactiveMap extends Map {
return this.#sources.keys();
}
*values() {
values() {
get(this.#version);
for (var source of this.#sources.values()) {
yield get(source);
}
return map(this.#sources.values(), get);
}
*entries() {
entries() {
get(this.#version);
for (var [key, source] of this.#sources.entries()) {
yield /** @type {[K, V]} */ ([key, get(source)]);
}
return map(
this.#sources.entries(),
([key, source]) => /** @type {[K, V]} */ ([key, get(source)])
);
}
[Symbol.iterator]() {

@ -1,6 +1,7 @@
import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { map } from './utils.js';
var read_methods = ['forEach', 'isDisjointFrom', 'isSubsetOf', 'isSupersetOf'];
var set_like_methods = ['difference', 'intersection', 'symmetricDifference', 'union'];
@ -141,10 +142,8 @@ export class ReactiveSet extends Set {
return this.keys();
}
*entries() {
for (var key of this.keys()) {
yield /** @type {[T, T]} */ ([key, key]);
}
entries() {
return map(this.keys(), (key) => /** @type {[T, T]} */ ([key, key]));
}
[Symbol.iterator]() {

@ -0,0 +1,24 @@
/**
* @template T
* @template U
* @param {Iterable<T>} iterable
* @param {(value: T) => U} fn
* @returns {IterableIterator<U>}
*/
export function map(iterable, fn) {
return {
[Symbol.iterator]: get_this,
next() {
for (const value of iterable) {
return { done: false, value: fn(value) };
}
return { done: true, value: undefined };
}
};
}
/** @this {any} */
function get_this() {
return this;
}
Loading…
Cancel
Save