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

Function capture

packages/svelte/src/internal/client/reactivity/async.js:130–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

128 * causes `b` to be registered as a dependency).
129 */
130export function capture() {
131 var previous_effect = /** @type {Effect} */ (active_effect);
132 var previous_reaction = active_reaction;
133 var previous_component_context = component_context;
134 var previous_batch = /** @type {Batch} */ (current_batch);
135
136 if (DEV) {
137 var previous_dev_stack = dev_stack;
138 }
139
140 return function restore(activate_batch = true) {
141 set_active_effect(previous_effect);
142 set_active_reaction(previous_reaction);
143 set_component_context(previous_component_context);
144
145 if (activate_batch && (previous_effect.f & DESTROYED) === 0) {
146 // TODO we only need optional chaining here because `{#await ...}` blocks
147 // are anomalous. Once we retire them we can get rid of it
148 previous_batch?.activate();
149 previous_batch?.apply();
150 }
151
152 if (DEV) {
153 set_reactivity_loss_tracker(null);
154 set_dev_stack(previous_dev_stack);
155 }
156 };
157}
158
159/**
160 * Wraps an `await` expression in such a way that the effect context that was

Callers 4

await_blockFunction · 0.90
flattenFunction · 0.85
saveFunction · 0.85
runFunction · 0.85

Calls 7

set_active_effectFunction · 0.90
set_active_reactionFunction · 0.90
set_component_contextFunction · 0.90
set_dev_stackFunction · 0.90
activateMethod · 0.80
applyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…