pull/16239/head
Rich Harris 2 months ago
parent 3ab41d6d07
commit 69ebe29417

@ -1,10 +1,9 @@
/** @import { Reaction, Source } from '#client' */
/** @import { Source } from '#client' */
import { DEV } from 'esm-env';
import { set, source, state } from '../internal/client/reactivity/sources.js';
import { label, tag } from '../internal/client/dev/tracing.js';
import { active_reaction, get, update_version } from '../internal/client/runtime.js';
import { get, update_version } from '../internal/client/runtime.js';
import { increment } from './utils.js';
import { teardown } from '../internal/client/reactivity/effects.js';
/**
* A reactive version of the built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object.
@ -57,7 +56,7 @@ export class SvelteMap extends Map {
#sources = new Map();
#version = state(0);
#size = state(0);
#update_version = -1;
#update_version = update_version || -1;
/**
* @param {Iterable<readonly [K, V]> | null | undefined} [value]
@ -65,10 +64,6 @@ export class SvelteMap extends Map {
constructor(value) {
super();
if (active_reaction !== null) {
this.#update_version = update_version;
}
if (DEV) {
// If the value is invalid then the native exception will fire here
value = new Map(value);
@ -95,11 +90,7 @@ export class SvelteMap extends Map {
* @returns {Source<T>}
*/
#source(value) {
if (update_version === this.#update_version) {
return state(value);
}
return source(value);
return update_version === this.#update_version ? state(value) : source(value);
}
/** @param {K} key */

@ -1,10 +1,9 @@
/** @import { Reaction, Source } from '#client' */
/** @import { Source } from '#client' */
import { DEV } from 'esm-env';
import { source, set, state } from '../internal/client/reactivity/sources.js';
import { label, tag } from '../internal/client/dev/tracing.js';
import { active_reaction, get, update_version } from '../internal/client/runtime.js';
import { get, update_version } from '../internal/client/runtime.js';
import { increment } from './utils.js';
import { teardown } from '../internal/client/reactivity/effects.js';
var read_methods = ['forEach', 'isDisjointFrom', 'isSubsetOf', 'isSupersetOf'];
var set_like_methods = ['difference', 'intersection', 'symmetricDifference', 'union'];
@ -51,7 +50,7 @@ export class SvelteSet extends Set {
#sources = new Map();
#version = state(0);
#size = state(0);
#update_version = -1;
#update_version = update_version || -1;
/**
* @param {Iterable<T> | null | undefined} [value]
@ -59,10 +58,6 @@ export class SvelteSet extends Set {
constructor(value) {
super();
if (active_reaction !== null) {
this.#update_version = update_version;
}
if (DEV) {
// If the value is invalid then the native exception will fire here
value = new Set(value);
@ -91,10 +86,7 @@ export class SvelteSet extends Set {
* @returns {Source<T>}
*/
#source(value) {
if (this.#update_version === update_version) {
return state(value);
}
return source(value);
return update_version === this.#update_version ? state(value) : source(value);
}
// We init as part of the first instance so that we can treeshake this class

Loading…
Cancel
Save