Home / Class/ SvelteMap Class — svelte Architecture

SvelteMap Class — svelte Architecture

Architecture documentation for the SvelteMap class in map.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  f49779c1_f219_37b0_968a_883379ecd32c["SvelteMap"]
  eb632f3e_6e0f_71bf_8ae3_df1fb779f36f["map.js"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|defined in| eb632f3e_6e0f_71bf_8ae3_df1fb779f36f
  5c4ba0c1_a105_1c1d_27a4_4abc1d9e72ab["constructor()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| 5c4ba0c1_a105_1c1d_27a4_4abc1d9e72ab
  a41d3e51_fb60_74cb_cf96_359ed10bba6e["value()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| a41d3e51_fb60_74cb_cf96_359ed10bba6e
  4176dd08_b6e9_0359_b4b0_bd7bf7ff3d2d["has()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| 4176dd08_b6e9_0359_b4b0_bd7bf7ff3d2d
  a1c3014f_988e_c060_a2b6_4a087dd877d0["forEach()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| a1c3014f_988e_c060_a2b6_4a087dd877d0
  0ad1774b_99d2_2c89_1068_0a26e5151b9a["get()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| 0ad1774b_99d2_2c89_1068_0a26e5151b9a
  c4654be9_603f_7b49_e404_23ea06eb0af5["set()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| c4654be9_603f_7b49_e404_23ea06eb0af5
  93c3f10b_1e5e_7023_b942_665d846b5985["delete()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| 93c3f10b_1e5e_7023_b942_665d846b5985
  2145e21f_9b2c_e7de_4893_b095e5024719["clear()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| 2145e21f_9b2c_e7de_4893_b095e5024719
  ff991bf8_6eb2_99d4_111b_79e03d3bdc70["keys()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| ff991bf8_6eb2_99d4_111b_79e03d3bdc70
  5deae257_db0a_986e_2f65_97557f6f29b6["values()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| 5deae257_db0a_986e_2f65_97557f6f29b6
  1872347e_369e_e816_5c67_ab703eae9547["entries()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| 1872347e_369e_e816_5c67_ab703eae9547
  afba4953_90bb_3f0c_d9a2_ddefdfa2e4d0["Symbol()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| afba4953_90bb_3f0c_d9a2_ddefdfa2e4d0
  dc6ea8ca_e321_b88f_7ea7_13c1919a4286["size()"]
  f49779c1_f219_37b0_968a_883379ecd32c -->|method| dc6ea8ca_e321_b88f_7ea7_13c1919a4286

Relationship Graph

Source Code

packages/svelte/src/reactivity/map.js lines 53–273

export class SvelteMap extends Map {
	/** @type {Map<K, Source<number>>} */
	#sources = new Map();
	#version = state(0);
	#size = state(0);
	#update_version = update_version || -1;

	/**
	 * @param {Iterable<readonly [K, V]> | null | undefined} [value]
	 */
	constructor(value) {
		super();

		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) {
				super.set(key, v);
			}
			this.#size.v = super.size;
		}
	}

	/**
	 * If the source is being created inside the same reaction as the SvelteMap instance,
	 * we use `state` so that it will not be a dependency of the reaction. Otherwise we
	 * use `source` so it will be.
	 *
	 * @template T
	 * @param {T} value
	 * @returns {Source<T>}
	 */
	#source(value) {
		return update_version === this.#update_version ? state(value) : source(value);
	}

	/** @param {K} key */
	has(key) {
		var sources = this.#sources;
		var s = sources.get(key);

		if (s === undefined) {
			var ret = super.get(key);
			if (ret !== undefined) {
				s = this.#source(0);

				if (DEV) {
					tag(s, `SvelteMap get(${label(key)})`);
				}

				sources.set(key, s);
			} else {
				// We should always track the version in case
				// the Set ever gets this value in the future.
				get(this.#version);
				return false;
			}
		}

		get(s);
		return true;
	}

	/**
	 * @param {(value: V, key: K, map: Map<K, V>) => void} callbackfn
	 * @param {any} [this_arg]
	 */
	forEach(callbackfn, this_arg) {
		this.#read_all();
		super.forEach(callbackfn, this_arg);
	}

	/** @param {K} key */
	get(key) {
		var sources = this.#sources;

Frequently Asked Questions

What is the SvelteMap class?
SvelteMap is a class in the svelte codebase, defined in packages/svelte/src/reactivity/map.js.
Where is SvelteMap defined?
SvelteMap is defined in packages/svelte/src/reactivity/map.js at line 53.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free