only call mark_reactions when updating a source

pull/12272/head
Rich Harris 2 years ago
parent 3f2dc2e7ab
commit 20cbdbc887

@ -4,7 +4,6 @@ import {
current_effect, current_effect,
remove_reactions, remove_reactions,
set_signal_status, set_signal_status,
mark_reactions,
current_skip_reaction, current_skip_reaction,
update_reaction, update_reaction,
destroy_effect_children, destroy_effect_children,
@ -100,7 +99,6 @@ export function update_derived(derived) {
if (!derived.equals(value)) { if (!derived.equals(value)) {
derived.v = value; derived.v = value;
derived.version = increment_version(); derived.version = increment_version();
mark_reactions(derived, DIRTY, false);
} }
} }

@ -94,7 +94,8 @@ function create_effect(type, fn, sync, push = true) {
parent: is_root ? null : current_effect, parent: is_root ? null : current_effect,
prev: null, prev: null,
teardown: null, teardown: null,
transitions: null transitions: null,
version: 0
}; };
if (DEV) { if (DEV) {

@ -3,6 +3,8 @@ import type { ComponentContext, Dom, Equals, TemplateNode, TransitionManager } f
export interface Signal { export interface Signal {
/** Flags bitmask */ /** Flags bitmask */
f: number; f: number;
/** Write version */
version: number;
} }
export interface Value<V = unknown> extends Signal { export interface Value<V = unknown> extends Signal {
@ -12,8 +14,6 @@ export interface Value<V = unknown> extends Signal {
equals: Equals; equals: Equals;
/** The latest value for this signal */ /** The latest value for this signal */
v: V; v: V;
/** Write version */
version: number;
} }
export interface Reaction extends Signal { export interface Reaction extends Signal {

@ -163,6 +163,7 @@ export function check_dirtiness(reaction) {
return true; return true;
} }
var is_effect = (flags & EFFECT) !== 0;
var is_unowned = (flags & UNOWNED) !== 0; var is_unowned = (flags & UNOWNED) !== 0;
var is_disconnected = (flags & DISCONNECTED) !== 0; var is_disconnected = (flags & DISCONNECTED) !== 0;
@ -180,8 +181,11 @@ export function check_dirtiness(reaction) {
update_derived(/** @type {import('#client').Derived} **/ (dependency)); update_derived(/** @type {import('#client').Derived} **/ (dependency));
} }
if ((reaction.f & DIRTY) !== 0) { if (dependency.version > reaction.version) {
// `reaction` might now be dirty, as a result of calling `update_derived` is_dirty = true;
}
if (is_effect && is_dirty) {
return true; return true;
} }
@ -190,7 +194,7 @@ export function check_dirtiness(reaction) {
// if our dependency write version is higher. If it is then we can assume // if our dependency write version is higher. If it is then we can assume
// that state has changed to a newer version and thus this unowned signal // that state has changed to a newer version and thus this unowned signal
// is also dirty. // is also dirty.
if (dependency.version > /** @type {import('#client').Derived} */ (reaction).version) { if (is_dirty) {
return true; return true;
} }
@ -204,10 +208,6 @@ export function check_dirtiness(reaction) {
// It might be that the derived was was dereferenced from its dependencies but has now come alive again. // It might be that the derived was was dereferenced from its dependencies but has now come alive again.
// In thise case, we need to re-attach it to the graph and mark it dirty if any of its dependencies have // In thise case, we need to re-attach it to the graph and mark it dirty if any of its dependencies have
// changed since. // changed since.
if (dependency.version > /** @type {import('#client').Derived} */ (reaction).version) {
is_dirty = true;
}
reactions = dependency.reactions; reactions = dependency.reactions;
if (reactions === null) { if (reactions === null) {
dependency.reactions = [reaction]; dependency.reactions = [reaction];
@ -490,6 +490,8 @@ export function update_effect(effect) {
execute_effect_teardown(effect); execute_effect_teardown(effect);
var teardown = update_reaction(effect); var teardown = update_reaction(effect);
effect.teardown = typeof teardown === 'function' ? teardown : null; effect.teardown = typeof teardown === 'function' ? teardown : null;
effect.version = current_version;
} catch (error) { } catch (error) {
handle_error(/** @type {Error} */ (error), effect, current_component_context); handle_error(/** @type {Error} */ (error), effect, current_component_context);
} finally { } finally {

Loading…
Cancel
Save