pull/10760/head
Rich Harris 2 years ago
parent 6c8c58738e
commit ecf3ead177

@ -161,7 +161,7 @@ export function batch_inspect(target, prop, receiver) {
}
/**
* @param {import('./types.js').Signal} signal
* @param {import('./types.js').Reaction} signal
* @returns {boolean}
*/
function is_signal_dirty(signal) {
@ -170,13 +170,16 @@ function is_signal_dirty(signal) {
return true;
}
if ((flags & MAYBE_DIRTY) !== 0) {
const dependencies = /** @type {import('./types.js').Reaction} **/ (signal).deps;
const dependencies = signal.deps;
if (dependencies !== null) {
const length = dependencies.length;
let i;
for (i = 0; i < length; i++) {
const dependency = dependencies[i];
if ((dependency.f & MAYBE_DIRTY) !== 0 && !is_signal_dirty(dependency)) {
if (
(dependency.f & MAYBE_DIRTY) !== 0 &&
!is_signal_dirty(/** @type {import('#client').Derived} */ (dependency))
) {
set_signal_status(dependency, CLEAN);
continue;
}
@ -214,16 +217,18 @@ function is_signal_dirty(signal) {
* @param {import('./types.js').Reaction} signal
* @returns {V}
*/
function execute_signal_fn(signal) {
function execute_reaction_fn(signal) {
const fn = signal.fn;
const flags = signal.f;
const is_render_effect = (flags & RENDER_EFFECT) !== 0;
const previous_dependencies = current_dependencies;
const previous_dependencies_index = current_dependencies_index;
const previous_untracked_writes = current_untracked_writes;
const previous_reaction = current_reaction;
const previous_skip_reaction = current_skip_reaction;
const is_render_effect = (flags & RENDER_EFFECT) !== 0;
const previous_untracking = current_untracking;
current_dependencies = /** @type {null | import('./types.js').Value[]} */ (null);
current_dependencies_index = 0;
current_untracked_writes = null;
@ -341,7 +346,7 @@ function remove_reaction(signal, dependency) {
if (reactions_length === 0 && (dependency.f & UNOWNED) !== 0) {
// If the signal is unowned then we need to make sure to change it to dirty.
set_signal_status(dependency, DIRTY);
remove_reactions(/** @type {import('./types.js').Reaction} **/ (dependency), 0);
remove_reactions(/** @type {import('./types.js').Derived} **/ (dependency), 0);
}
}
@ -424,7 +429,7 @@ export function execute_effect(signal) {
if (teardown !== null) {
teardown();
}
const possible_teardown = execute_signal_fn(signal);
const possible_teardown = execute_reaction_fn(signal);
if (typeof possible_teardown === 'function') {
signal.v = possible_teardown;
}
@ -693,7 +698,7 @@ function update_derived(signal, force_schedule) {
const previous_updating_derived = updating_derived;
updating_derived = true;
destroy_references(signal);
const value = execute_signal_fn(signal);
const value = execute_reaction_fn(signal);
updating_derived = previous_updating_derived;
const status =
(current_skip_reaction || (signal.f & UNOWNED) !== 0) && signal.deps !== null
@ -767,7 +772,10 @@ export function get(signal) {
}
}
if ((flags & DERIVED) !== 0 && is_signal_dirty(signal)) {
if (
(flags & DERIVED) !== 0 &&
is_signal_dirty(/** @type {import('#client').Derived} */ (signal))
) {
if (DEV) {
// we want to avoid tracking indirect dependencies
const previous_inspect_fn = inspect_fn;

@ -11,7 +11,7 @@ import {
SNIPPET_BLOCK,
STATE_SYMBOL
} from './constants.js';
import type { Reaction, Effect, Signal, Source, Value } from './reactivity/types.js';
import type { Effect, Source, Value } from './reactivity/types.js';
type EventCallback = (event: Event) => boolean;
export type EventCallbackMap = Record<string, EventCallback | EventCallback[]>;
@ -99,7 +99,7 @@ export type RootBlock = {
/** dom */
d: null | TemplateNode | Array<TemplateNode>;
/** effect */
e: null | Reaction;
e: null | Effect;
/** intro */
i: boolean;
/** parent */
@ -150,7 +150,7 @@ export type HeadBlock = {
/** dom */
d: null | TemplateNode | Array<TemplateNode>;
/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */
p: Block;
/** transition */
@ -163,7 +163,7 @@ export type DynamicElementBlock = {
/** dom */
d: null | TemplateNode | Array<TemplateNode>;
/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */
p: Block;
/** transition */
@ -176,7 +176,7 @@ export type DynamicComponentBlock = {
/** dom */
d: null | TemplateNode | Array<TemplateNode>;
/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */
p: Block;
/** transition */
@ -189,7 +189,7 @@ export type AwaitBlock = {
/** dom */
d: null | TemplateNode | Array<TemplateNode>;
/** effect */
e: null | Reaction;
e: null | Effect;
/** parent */
p: Block;
/** pending */
@ -210,7 +210,7 @@ export type EachBlock = {
/** items */
v: EachItemBlock[];
/** effewct */
e: null | Reaction;
e: null | Effect;
/** parent */
p: Block;
/** transition */
@ -250,7 +250,7 @@ export type SnippetBlock = {
/** parent */
p: Block;
/** effect */
e: null | Reaction;
e: null | Effect;
/** transition */
r: null;
/** type */

Loading…
Cancel
Save