MCPcopy
hub / github.com/sveltejs/svelte / set

Method set

packages/svelte/src/reactivity/map.js:160–193  ·  view source on GitHub ↗

* @param {K} key * @param {V} value *

(key, value)

Source from the content-addressed store, hash-verified

158 * @param {V} value
159 * */
160 set(key, value) {
161 var sources = this.#sources;
162 var s = sources.get(key);
163 var prev_res = super.get(key);
164 var res = super.set(key, value);
165 var version = this.#version;
166
167 if (s === undefined) {
168 s = this.#source(0);
169
170 if (DEV) {
171 tag(s, `SvelteMap get(${label(key)})`);
172 }
173
174 sources.set(key, s);
175 set(this.#size, super.size);
176 increment(version);
177 } else if (prev_res !== value) {
178 increment(s);
179
180 // if not every reaction of s is a reaction of version we need to also include version
181 var v_reactions = version.reactions === null ? null : new Set(version.reactions);
182 var needs_version_increase =
183 v_reactions === null ||
184 !s.reactions?.every((r) =>
185 /** @type {NonNullable<typeof v_reactions>} */ (v_reactions).has(r)
186 );
187 if (needs_version_increase) {
188 increment(version);
189 }
190 }
191
192 return res;
193 }
194
195 /** @param {K} key */
196 delete(key) {

Callers

nothing calls this directly

Calls 8

#sourceMethod · 0.95
tagFunction · 0.90
labelFunction · 0.90
setFunction · 0.90
incrementFunction · 0.90
setMethod · 0.65
getMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected