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

Function internal_set

packages/svelte/src/internal/client/reactivity/sources.js:181–262  ·  view source on GitHub ↗
(source, value, updated_during_traversal = null)

Source from the content-addressed store, hash-verified

179 * @returns {V}
180 */
181export function internal_set(source, value, updated_during_traversal = null) {
182 if (!source.equals(value)) {
183 old_values.set(source, is_destroying_effect ? value : source.v);
184
185 var batch = Batch.ensure();
186 batch.capture(source, value);
187
188 if (DEV) {
189 if (tracing_mode_flag || active_effect !== null) {
190 source.updated ??= new Map();
191
192 // For performance reasons, when not using $inspect.trace, we only start collecting stack traces
193 // after the same source has been updated more than 5 times in the same flush cycle.
194 const count = (source.updated.get('')?.count ?? 0) + 1;
195 source.updated.set('', { error: /** @type {any} */ (null), count });
196
197 if (tracing_mode_flag || count > 5) {
198 const error = get_error('updated at');
199
200 if (error !== null) {
201 let entry = source.updated.get(error.stack);
202
203 if (!entry) {
204 entry = { error, count: 0 };
205 source.updated.set(error.stack, entry);
206 }
207
208 entry.count++;
209 }
210 }
211 }
212
213 if (active_effect !== null) {
214 source.set_during_effect = true;
215 }
216 }
217
218 if ((source.f & DERIVED) !== 0) {
219 const derived = /** @type {Derived} */ (source);
220
221 // if we are assigning to a dirty derived we set it to clean/maybe dirty but we also eagerly execute it to track the dependencies
222 if ((source.f & DIRTY) !== 0) {
223 execute_derived(derived);
224 }
225
226 // During time traveling we don't want to reset the status so that
227 // traversal of the graph in the other batches still happens
228 if (batch_values === null) {
229 update_derived_status(derived);
230 }
231 }
232
233 source.wv = increment_write_version();
234
235 // For debugging, in case you want to know which reactions are being scheduled:
236 // log_reactions(source);
237 mark_reactions(source, DIRTY, updated_during_traversal);
238

Callers 6

invalidate_inner_signalsFunction · 0.90
eachFunction · 0.90
await_blockFunction · 0.90
update_pending_countMethod · 0.90
handlerFunction · 0.90
setFunction · 0.85

Calls 13

get_errorFunction · 0.90
execute_derivedFunction · 0.90
update_derived_statusFunction · 0.90
increment_write_versionFunction · 0.90
is_runesFunction · 0.90
set_untracked_writesFunction · 0.90
mark_reactionsFunction · 0.85
flush_eager_effectsFunction · 0.85
captureMethod · 0.80
pushMethod · 0.80
setMethod · 0.65
ensureMethod · 0.45

Tested by

no test coverage detected