|
|
|
@ -1,8 +1,9 @@
|
|
|
|
|
/** @import { Source } from '#client' */
|
|
|
|
|
import { DEV } from 'esm-env';
|
|
|
|
|
import { set, source } from '../internal/client/reactivity/sources.js';
|
|
|
|
|
import { tag } from '../internal/client/dev/tracing.js';
|
|
|
|
|
import { get } from '../internal/client/runtime.js';
|
|
|
|
|
import { increment, tag_if_necessary } from './utils.js';
|
|
|
|
|
import { increment } from './utils.js';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A reactive version of the built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object.
|
|
|
|
@ -53,8 +54,8 @@ import { increment, tag_if_necessary } from './utils.js';
|
|
|
|
|
export class SvelteMap extends Map {
|
|
|
|
|
/** @type {Map<K, Source<number>>} */
|
|
|
|
|
#sources = new Map();
|
|
|
|
|
#version = tag_if_necessary(source(0), 'SvelteMap version');
|
|
|
|
|
#size = tag_if_necessary(source(0), 'SvelteMap.size');
|
|
|
|
|
#version = source(0);
|
|
|
|
|
#size = source(0);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Iterable<readonly [K, V]> | null | undefined} [value]
|
|
|
|
@ -62,8 +63,13 @@ export class SvelteMap extends Map {
|
|
|
|
|
constructor(value) {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
// If the value is invalid then the native exception will fire here
|
|
|
|
|
if (DEV) value = new Map(value);
|
|
|
|
|
if (DEV) {
|
|
|
|
|
// If the value is invalid then the native exception will fire here
|
|
|
|
|
value = new Map(value);
|
|
|
|
|
|
|
|
|
|
tag(this.#version, 'SvelteMap version');
|
|
|
|
|
tag(this.#size, 'SvelteMap.size');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
|
for (var [key, v] of value) {
|
|
|
|
@ -81,10 +87,13 @@ export class SvelteMap extends Map {
|
|
|
|
|
if (s === undefined) {
|
|
|
|
|
var ret = super.get(key);
|
|
|
|
|
if (ret !== undefined) {
|
|
|
|
|
s = tag_if_necessary(
|
|
|
|
|
source(0),
|
|
|
|
|
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
|
|
|
|
|
);
|
|
|
|
|
s = source(0);
|
|
|
|
|
|
|
|
|
|
if (DEV) {
|
|
|
|
|
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
|
|
|
|
|
tag(s, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sources.set(key, s);
|
|
|
|
|
} else {
|
|
|
|
|
// We should always track the version in case
|
|
|
|
@ -115,10 +124,13 @@ export class SvelteMap extends Map {
|
|
|
|
|
if (s === undefined) {
|
|
|
|
|
var ret = super.get(key);
|
|
|
|
|
if (ret !== undefined) {
|
|
|
|
|
s = tag_if_necessary(
|
|
|
|
|
source(0),
|
|
|
|
|
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
|
|
|
|
|
);
|
|
|
|
|
s = source(0);
|
|
|
|
|
|
|
|
|
|
if (DEV) {
|
|
|
|
|
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
|
|
|
|
|
tag(s, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sources.set(key, s);
|
|
|
|
|
} else {
|
|
|
|
|
// We should always track the version in case
|
|
|
|
@ -144,13 +156,14 @@ export class SvelteMap extends Map {
|
|
|
|
|
var version = this.#version;
|
|
|
|
|
|
|
|
|
|
if (s === undefined) {
|
|
|
|
|
sources.set(
|
|
|
|
|
key,
|
|
|
|
|
tag_if_necessary(
|
|
|
|
|
source(0),
|
|
|
|
|
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
s = source(0);
|
|
|
|
|
|
|
|
|
|
if (DEV) {
|
|
|
|
|
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
|
|
|
|
|
tag(s, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sources.set(key, s);
|
|
|
|
|
set(this.#size, super.size);
|
|
|
|
|
increment(version);
|
|
|
|
|
} else if (prev_res !== value) {
|
|
|
|
@ -209,18 +222,19 @@ export class SvelteMap extends Map {
|
|
|
|
|
if (this.#size.v !== sources.size) {
|
|
|
|
|
for (var key of super.keys()) {
|
|
|
|
|
if (!sources.has(key)) {
|
|
|
|
|
sources.set(
|
|
|
|
|
key,
|
|
|
|
|
tag_if_necessary(
|
|
|
|
|
source(0),
|
|
|
|
|
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
var s = source(0);
|
|
|
|
|
|
|
|
|
|
if (DEV) {
|
|
|
|
|
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
|
|
|
|
|
tag(s, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sources.set(key, s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var [, s] of this.#sources) {
|
|
|
|
|
for ([, s] of this.#sources) {
|
|
|
|
|
get(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|