more efficient initialisation

pull/10803/head
Rich Harris 1 year ago
parent 503384def8
commit 29d4a8078b

@ -1,4 +1,3 @@
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';
@ -18,15 +17,14 @@ export class ReactiveMap extends Map {
* @param {Iterable<readonly [K, V]> | null | undefined} [value]
*/
constructor(value) {
super();
// If the value is invalid then the native exception will fire here
if (DEV) new Map(value);
super(value);
if (value) {
for (var [key, v] of value) {
this.set(key, v);
this.#sources.set(key, source(v));
}
this.#size.v = this.#sources.size;
}
}
@ -78,7 +76,7 @@ export class ReactiveMap extends Map {
/**
* @param {K} key
* @param {V} value
* */
*/
set(key, value) {
var sources = this.#sources;
var source_value = sources.get(key);

@ -1,4 +1,3 @@
import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { make_iterable } from './utils.js';
@ -21,10 +20,7 @@ export class ReactiveSet extends Set {
* @param {T[] | null} [value]
*/
constructor(value) {
super();
// If the value is invalid then the native exception will fire here
if (DEV) new Set(value);
super(value);
if (value) {
// Support set-like objects that have a keys() method
@ -34,8 +30,10 @@ export class ReactiveSet extends Set {
}
for (var element of value) {
this.add(/** @type {T} */ (element));
this.#sources.set(element, source(true));
}
this.#size.v = this.#sources.size;
}
if (!inited) this.#init();

Loading…
Cancel
Save