diff --git a/packages/svelte/src/reactivity/map.js b/packages/svelte/src/reactivity/map.js index 2aca3eeabb..319a680db0 100644 --- a/packages/svelte/src/reactivity/map.js +++ b/packages/svelte/src/reactivity/map.js @@ -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 | 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); diff --git a/packages/svelte/src/reactivity/set.js b/packages/svelte/src/reactivity/set.js index b9ade7a3d7..5c570e37fa 100644 --- a/packages/svelte/src/reactivity/set.js +++ b/packages/svelte/src/reactivity/set.js @@ -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();