|
|
|
@ -86,17 +86,17 @@ export function set_active_effect(effect) {
|
|
|
|
|
/**
|
|
|
|
|
* When sources are created within a reaction, reading and writing
|
|
|
|
|
* them within that reaction should not cause a re-run
|
|
|
|
|
* @type {null | [active_reaction: Reaction, sources: Source[]]}
|
|
|
|
|
* @type {null | { reaction: Reaction, sources: Source[] }}
|
|
|
|
|
*/
|
|
|
|
|
export let reaction_sources = null;
|
|
|
|
|
export let source_ownership = null;
|
|
|
|
|
|
|
|
|
|
/** @param {Value} value */
|
|
|
|
|
export function push_reaction_value(value) {
|
|
|
|
|
if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
|
|
|
|
|
if (reaction_sources === null) {
|
|
|
|
|
reaction_sources = [active_reaction, [value]];
|
|
|
|
|
if (source_ownership === null) {
|
|
|
|
|
source_ownership = { reaction: active_reaction, sources: [value] };
|
|
|
|
|
} else {
|
|
|
|
|
reaction_sources[1].push(value);
|
|
|
|
|
source_ownership.sources.push(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -235,7 +235,12 @@ function schedule_possible_effect_self_invalidation(signal, effect, root = true)
|
|
|
|
|
for (var i = 0; i < reactions.length; i++) {
|
|
|
|
|
var reaction = reactions[i];
|
|
|
|
|
|
|
|
|
|
if (reaction_sources?.[1].includes(signal) && reaction_sources[0] === active_reaction) continue;
|
|
|
|
|
if (
|
|
|
|
|
source_ownership?.reaction === active_reaction &&
|
|
|
|
|
source_ownership.sources.includes(signal)
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((reaction.f & DERIVED) !== 0) {
|
|
|
|
|
schedule_possible_effect_self_invalidation(/** @type {Derived} */ (reaction), effect, false);
|
|
|
|
@ -257,7 +262,7 @@ export function update_reaction(reaction) {
|
|
|
|
|
var previous_untracked_writes = untracked_writes;
|
|
|
|
|
var previous_reaction = active_reaction;
|
|
|
|
|
var previous_skip_reaction = skip_reaction;
|
|
|
|
|
var previous_reaction_sources = reaction_sources;
|
|
|
|
|
var previous_reaction_sources = source_ownership;
|
|
|
|
|
var previous_component_context = component_context;
|
|
|
|
|
var previous_untracking = untracking;
|
|
|
|
|
|
|
|
|
@ -270,7 +275,7 @@ export function update_reaction(reaction) {
|
|
|
|
|
(flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
|
|
|
|
|
active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
|
|
|
|
|
|
|
|
|
|
reaction_sources = null;
|
|
|
|
|
source_ownership = null;
|
|
|
|
|
set_component_context(reaction.ctx);
|
|
|
|
|
untracking = false;
|
|
|
|
|
read_version++;
|
|
|
|
@ -358,7 +363,7 @@ export function update_reaction(reaction) {
|
|
|
|
|
untracked_writes = previous_untracked_writes;
|
|
|
|
|
active_reaction = previous_reaction;
|
|
|
|
|
skip_reaction = previous_skip_reaction;
|
|
|
|
|
reaction_sources = previous_reaction_sources;
|
|
|
|
|
source_ownership = previous_reaction_sources;
|
|
|
|
|
set_component_context(previous_component_context);
|
|
|
|
|
untracking = previous_untracking;
|
|
|
|
|
|
|
|
|
@ -739,7 +744,10 @@ export function get(signal) {
|
|
|
|
|
|
|
|
|
|
// Register the dependency on the current reaction signal.
|
|
|
|
|
if (active_reaction !== null && !untracking) {
|
|
|
|
|
if (!reaction_sources?.[1].includes(signal) || reaction_sources[0] !== active_reaction) {
|
|
|
|
|
if (
|
|
|
|
|
source_ownership?.reaction !== active_reaction ||
|
|
|
|
|
!source_ownership?.sources.includes(signal)
|
|
|
|
|
) {
|
|
|
|
|
var deps = active_reaction.deps;
|
|
|
|
|
if (signal.rv < read_version) {
|
|
|
|
|
signal.rv = read_version;
|
|
|
|
|