|
|
|
@ -78,6 +78,10 @@ let dev_effect_stack = [];
|
|
|
|
|
/** @type {null | Reaction} */
|
|
|
|
|
export let active_reaction = null;
|
|
|
|
|
|
|
|
|
|
export let untracking = false;
|
|
|
|
|
|
|
|
|
|
export let unsafe_mutations = false;
|
|
|
|
|
|
|
|
|
|
/** @param {null | Reaction} reaction */
|
|
|
|
|
export function set_active_reaction(reaction) {
|
|
|
|
|
active_reaction = reaction;
|
|
|
|
@ -387,6 +391,8 @@ export function update_reaction(reaction) {
|
|
|
|
|
var previous_skip_reaction = skip_reaction;
|
|
|
|
|
var prev_derived_sources = derived_sources;
|
|
|
|
|
var previous_component_context = component_context;
|
|
|
|
|
var previous_untracking = untracking;
|
|
|
|
|
var previous_unsafe_mutations = unsafe_mutations;
|
|
|
|
|
var flags = reaction.f;
|
|
|
|
|
|
|
|
|
|
new_deps = /** @type {null | Value[]} */ (null);
|
|
|
|
@ -396,6 +402,8 @@ export function update_reaction(reaction) {
|
|
|
|
|
skip_reaction = !is_flushing_effect && (flags & UNOWNED) !== 0;
|
|
|
|
|
derived_sources = null;
|
|
|
|
|
component_context = reaction.ctx;
|
|
|
|
|
untracking = false;
|
|
|
|
|
unsafe_mutations = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var result = /** @type {Function} */ (0, reaction.fn)();
|
|
|
|
@ -434,6 +442,8 @@ export function update_reaction(reaction) {
|
|
|
|
|
skip_reaction = previous_skip_reaction;
|
|
|
|
|
derived_sources = prev_derived_sources;
|
|
|
|
|
component_context = previous_component_context;
|
|
|
|
|
untracking = previous_untracking;
|
|
|
|
|
unsafe_mutations = previous_unsafe_mutations;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -856,7 +866,7 @@ export function get(signal) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Register the dependency on the current reaction signal.
|
|
|
|
|
if (active_reaction !== null) {
|
|
|
|
|
if (active_reaction !== null && !untracking) {
|
|
|
|
|
if (derived_sources !== null && derived_sources.includes(signal)) {
|
|
|
|
|
e.state_unsafe_local_read();
|
|
|
|
|
}
|
|
|
|
@ -1016,12 +1026,31 @@ export function invalidate_inner_signals(fn) {
|
|
|
|
|
* @returns {T}
|
|
|
|
|
*/
|
|
|
|
|
export function untrack(fn) {
|
|
|
|
|
const previous_reaction = active_reaction;
|
|
|
|
|
var previous_untracking = untracking;
|
|
|
|
|
try {
|
|
|
|
|
active_reaction = null;
|
|
|
|
|
untracking = true;
|
|
|
|
|
return fn();
|
|
|
|
|
} finally {
|
|
|
|
|
active_reaction = previous_reaction;
|
|
|
|
|
untracking = previous_untracking;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When used inside a [`$derived`](https://svelte.dev/docs/svelte/$derived),
|
|
|
|
|
* any state updates to state is allowed.
|
|
|
|
|
*
|
|
|
|
|
* ```
|
|
|
|
|
* @template T
|
|
|
|
|
* @param {() => T} fn
|
|
|
|
|
* @returns {T}
|
|
|
|
|
*/
|
|
|
|
|
export function unsafe(fn) {
|
|
|
|
|
var previous_unsafe_mutations = unsafe_mutations;
|
|
|
|
|
try {
|
|
|
|
|
unsafe_mutations = true;
|
|
|
|
|
return fn();
|
|
|
|
|
} finally {
|
|
|
|
|
unsafe_mutations = previous_unsafe_mutations;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|