|
|
@ -87,17 +87,17 @@ export function set_active_effect(effect) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* When sources are created within a reaction, reading and writing
|
|
|
|
* When sources are created within a reaction, reading and writing
|
|
|
|
* them within that reaction should not cause a re-run
|
|
|
|
* them within that reaction should not cause a re-run
|
|
|
|
* @type {null | { reaction: Reaction, sources: Source[] }}
|
|
|
|
* @type {null | Source[]}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export let source_ownership = null;
|
|
|
|
export let current_sources = null;
|
|
|
|
|
|
|
|
|
|
|
|
/** @param {Value} value */
|
|
|
|
/** @param {Value} value */
|
|
|
|
export function push_reaction_value(value) {
|
|
|
|
export function push_reaction_value(value) {
|
|
|
|
if (active_reaction !== null && (!async_mode_flag || (active_reaction.f & DERIVED) !== 0)) {
|
|
|
|
if (active_reaction !== null && (!async_mode_flag || (active_reaction.f & DERIVED) !== 0)) {
|
|
|
|
if (source_ownership === null) {
|
|
|
|
if (current_sources === null) {
|
|
|
|
source_ownership = { reaction: active_reaction, sources: [value] };
|
|
|
|
current_sources = [value];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
source_ownership.sources.push(value);
|
|
|
|
current_sources.push(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -135,6 +135,11 @@ let read_version = 0;
|
|
|
|
|
|
|
|
|
|
|
|
export let update_version = read_version;
|
|
|
|
export let update_version = read_version;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @param {number} value */
|
|
|
|
|
|
|
|
export function set_update_version(value) {
|
|
|
|
|
|
|
|
update_version = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we are working with a get() chain that has no active container,
|
|
|
|
// If we are working with a get() chain that has no active container,
|
|
|
|
// to prevent memory leaks, we skip adding the reaction.
|
|
|
|
// to prevent memory leaks, we skip adding the reaction.
|
|
|
|
export let skip_reaction = false;
|
|
|
|
export let skip_reaction = false;
|
|
|
@ -239,11 +244,7 @@ function schedule_possible_effect_self_invalidation(signal, effect, root = true)
|
|
|
|
var reactions = signal.reactions;
|
|
|
|
var reactions = signal.reactions;
|
|
|
|
if (reactions === null) return;
|
|
|
|
if (reactions === null) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (!async_mode_flag && current_sources?.includes(signal)) {
|
|
|
|
!async_mode_flag &&
|
|
|
|
|
|
|
|
source_ownership?.reaction === active_reaction &&
|
|
|
|
|
|
|
|
source_ownership.sources.includes(signal)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -270,7 +271,7 @@ export function update_reaction(reaction) {
|
|
|
|
var previous_untracked_writes = untracked_writes;
|
|
|
|
var previous_untracked_writes = untracked_writes;
|
|
|
|
var previous_reaction = active_reaction;
|
|
|
|
var previous_reaction = active_reaction;
|
|
|
|
var previous_skip_reaction = skip_reaction;
|
|
|
|
var previous_skip_reaction = skip_reaction;
|
|
|
|
var previous_reaction_sources = source_ownership;
|
|
|
|
var previous_sources = current_sources;
|
|
|
|
var previous_component_context = component_context;
|
|
|
|
var previous_component_context = component_context;
|
|
|
|
var previous_untracking = untracking;
|
|
|
|
var previous_untracking = untracking;
|
|
|
|
var previous_update_version = update_version;
|
|
|
|
var previous_update_version = update_version;
|
|
|
@ -284,7 +285,7 @@ export function update_reaction(reaction) {
|
|
|
|
(flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
|
|
|
|
(flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
|
|
|
|
active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
|
|
|
|
active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
|
|
|
|
|
|
|
|
|
|
|
|
source_ownership = null;
|
|
|
|
current_sources = null;
|
|
|
|
set_component_context(reaction.ctx);
|
|
|
|
set_component_context(reaction.ctx);
|
|
|
|
untracking = false;
|
|
|
|
untracking = false;
|
|
|
|
update_version = ++read_version;
|
|
|
|
update_version = ++read_version;
|
|
|
@ -376,7 +377,7 @@ export function update_reaction(reaction) {
|
|
|
|
untracked_writes = previous_untracked_writes;
|
|
|
|
untracked_writes = previous_untracked_writes;
|
|
|
|
active_reaction = previous_reaction;
|
|
|
|
active_reaction = previous_reaction;
|
|
|
|
skip_reaction = previous_skip_reaction;
|
|
|
|
skip_reaction = previous_skip_reaction;
|
|
|
|
source_ownership = previous_reaction_sources;
|
|
|
|
current_sources = previous_sources;
|
|
|
|
set_component_context(previous_component_context);
|
|
|
|
set_component_context(previous_component_context);
|
|
|
|
untracking = previous_untracking;
|
|
|
|
untracking = previous_untracking;
|
|
|
|
update_version = previous_update_version;
|
|
|
|
update_version = previous_update_version;
|
|
|
@ -550,10 +551,7 @@ export function get(signal) {
|
|
|
|
// we don't add the dependency, because that would create a memory leak
|
|
|
|
// we don't add the dependency, because that would create a memory leak
|
|
|
|
var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
|
|
|
|
var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
|
|
|
|
|
|
|
|
|
|
|
|
var is_owned_by_reaction =
|
|
|
|
if (!destroyed && !current_sources?.includes(signal)) {
|
|
|
|
source_ownership?.reaction === active_reaction && source_ownership.sources.includes(signal);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!destroyed && !is_owned_by_reaction) {
|
|
|
|
|
|
|
|
var deps = active_reaction.deps;
|
|
|
|
var deps = active_reaction.deps;
|
|
|
|
|
|
|
|
|
|
|
|
if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
|
|
|
|
if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
|
|
|
|