rename inspect effects to eager effects, run them in prod

pull/17004/head
Rich Harris 4 weeks ago
parent 53cc91dd0c
commit 8285fc6c4f

@ -16,7 +16,7 @@ export const DESTROYED = 1 << 14;
export const EFFECT_RAN = 1 << 15;
/** 'Transparent' effects do not create a transition boundary */
export const EFFECT_TRANSPARENT = 1 << 16;
export const INSPECT_EFFECT = 1 << 17;
export const EAGER_EFFECT = 1 << 17;
export const HEAD_EFFECT = 1 << 18;
export const EFFECT_PRESERVED = 1 << 19;
export const USER_EFFECT = 1 << 20;

@ -1,6 +1,6 @@
import { UNINITIALIZED } from '../../../constants.js';
import { snapshot } from '../../shared/clone.js';
import { inspect_effect, render_effect, validate_effect } from '../reactivity/effects.js';
import { eager_effect, render_effect, validate_effect } from '../reactivity/effects.js';
import { untrack } from '../runtime.js';
import { get_stack } from './tracing.js';
@ -19,7 +19,7 @@ export function inspect(get_value, inspector, show_stack = false) {
// stack traces. As a consequence, reading the value might result
// in an error (an `$inspect(object.property)` will run before the
// `{#if object}...{/if}` that contains it)
inspect_effect(() => {
eager_effect(() => {
try {
var value = get_value();
} catch (e) {

@ -19,8 +19,8 @@ import {
state as source,
set,
increment,
flush_inspect_effects,
set_inspect_effects_deferred
flush_eager_effects,
set_eager_effects_deferred
} from './reactivity/sources.js';
import { PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
import { UNINITIALIZED } from '../../constants.js';
@ -421,9 +421,9 @@ function inspectable_array(array) {
* @param {any[]} args
*/
return function (...args) {
set_inspect_effects_deferred();
set_eager_effects_deferred();
var result = value.apply(this, args);
flush_inspect_effects();
flush_eager_effects();
return result;
};
}

@ -13,7 +13,7 @@ import {
MAYBE_DIRTY,
DERIVED,
BOUNDARY_EFFECT,
INSPECT_EFFECT
EAGER_EFFECT
} from '#client/constants';
import { async_mode_flag } from '../../flags/index.js';
import { deferred, define_property } from '../../shared/utils.js';
@ -33,14 +33,14 @@ import { flush_tasks, queue_micro_task } from '../dom/task.js';
import { DEV } from 'esm-env';
import { invoke_error_boundary } from '../error-handling.js';
import {
flush_inspect_effects,
inspect_effects,
flush_eager_effects,
eager_effects,
old_values,
set_inspect_effects,
set_eager_effects,
source,
update
} from './sources.js';
import { inspect_effect, unlink_effect } from './effects.js';
import { eager_effect, unlink_effect } from './effects.js';
/**
* @typedef {{
@ -745,14 +745,14 @@ function mark_effects(value, sources, marked, checked) {
* @param {Value} value
* @param {Set<Effect>} effects
*/
function mark_inspect_effects(value, effects) {
function mark_eager_effects(value, effects) {
if (value.reactions !== null) {
for (const reaction of value.reactions) {
const flags = reaction.f;
if ((flags & DERIVED) !== 0) {
mark_inspect_effects(/** @type {Derived} */ (reaction), effects);
} else if ((flags & INSPECT_EFFECT) !== 0) {
mark_eager_effects(/** @type {Derived} */ (reaction), effects);
} else if ((flags & EAGER_EFFECT) !== 0) {
set_signal_status(reaction, DIRTY);
effects.add(/** @type {Effect} */ (reaction));
}
@ -841,7 +841,7 @@ export function eager(fn) {
get(version);
inspect_effect(() => {
eager_effect(() => {
if (initial) {
// the first time this runs, we create an inspect effect
// that will run eagerly whenever the expression changes
@ -918,14 +918,14 @@ export function fork(fn) {
// trigger any `$state.eager(...)` expressions with the new state
flushSync(() => {
/** @type {Set<Effect>} */
const inspect_effects = new Set();
const eager_effects = new Set();
for (const source of batch.current.keys()) {
mark_inspect_effects(source, inspect_effects);
mark_eager_effects(source, eager_effects);
}
set_inspect_effects(inspect_effects);
flush_inspect_effects();
set_eager_effects(eager_effects);
flush_eager_effects();
});
batch.revive();

@ -28,7 +28,7 @@ import { equals, safe_equals } from './equality.js';
import * as e from '../errors.js';
import * as w from '../warnings.js';
import { async_effect, destroy_effect, teardown } from './effects.js';
import { inspect_effects, internal_set, set_inspect_effects, source } from './sources.js';
import { eager_effects, internal_set, set_eager_effects, source } from './sources.js';
import { get_stack } from '../dev/tracing.js';
import { async_mode_flag, tracing_mode_flag } from '../../flags/index.js';
import { Boundary } from '../dom/blocks/boundary.js';
@ -318,8 +318,8 @@ export function execute_derived(derived) {
set_active_effect(get_derived_parent_effect(derived));
if (DEV) {
let prev_inspect_effects = inspect_effects;
set_inspect_effects(new Set());
let prev_eager_effects = eager_effects;
set_eager_effects(new Set());
try {
if (stack.includes(derived)) {
e.derived_references_self();
@ -332,7 +332,7 @@ export function execute_derived(derived) {
value = update_reaction(derived);
} finally {
set_active_effect(prev_active_effect);
set_inspect_effects(prev_inspect_effects);
set_eager_effects(prev_eager_effects);
stack.pop();
}
} else {

@ -27,7 +27,7 @@ import {
DERIVED,
UNOWNED,
CLEAN,
INSPECT_EFFECT,
EAGER_EFFECT,
HEAD_EFFECT,
MAYBE_DIRTY,
EFFECT_PRESERVED,
@ -88,7 +88,7 @@ function create_effect(type, fn, sync, push = true) {
if (DEV) {
// Ensure the parent is never an inspect effect
while (parent !== null && (parent.f & INSPECT_EFFECT) !== 0) {
while (parent !== null && (parent.f & EAGER_EFFECT) !== 0) {
parent = parent.parent;
}
}
@ -242,8 +242,8 @@ export function user_pre_effect(fn) {
}
/** @param {() => void | (() => void)} fn */
export function inspect_effect(fn) {
return create_effect(INSPECT_EFFECT, fn, true);
export function eager_effect(fn) {
return create_effect(EAGER_EFFECT, fn, true);
}
/**

@ -22,7 +22,7 @@ import {
DERIVED,
DIRTY,
BRANCH_EFFECT,
INSPECT_EFFECT,
EAGER_EFFECT,
UNOWNED,
MAYBE_DIRTY,
BLOCK_EFFECT,
@ -39,7 +39,7 @@ import { proxy } from '../proxy.js';
import { execute_derived } from './deriveds.js';
/** @type {Set<any>} */
export let inspect_effects = new Set();
export let eager_effects = new Set();
/** @type {Map<Source, any>} */
export const old_values = new Map();
@ -47,14 +47,14 @@ export const old_values = new Map();
/**
* @param {Set<any>} v
*/
export function set_inspect_effects(v) {
inspect_effects = v;
export function set_eager_effects(v) {
eager_effects = v;
}
let inspect_effects_deferred = false;
let eager_effects_deferred = false;
export function set_inspect_effects_deferred() {
inspect_effects_deferred = true;
export function set_eager_effects_deferred() {
eager_effects_deferred = true;
}
/**
@ -146,9 +146,9 @@ export function set(source, value, should_proxy = false) {
active_reaction !== null &&
// since we are untracking the function inside `$inspect.with` we need to add this check
// to ensure we error if state is set inside an inspect effect
(!untracking || (active_reaction.f & INSPECT_EFFECT) !== 0) &&
(!untracking || (active_reaction.f & EAGER_EFFECT) !== 0) &&
is_runes() &&
(active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | INSPECT_EFFECT)) !== 0 &&
(active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | EAGER_EFFECT)) !== 0 &&
!current_sources?.includes(source)
) {
e.state_unsafe_mutation();
@ -235,18 +235,18 @@ export function internal_set(source, value) {
}
}
if (DEV && !batch.is_fork && inspect_effects.size > 0 && !inspect_effects_deferred) {
flush_inspect_effects();
if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
flush_eager_effects();
}
}
return value;
}
export function flush_inspect_effects() {
inspect_effects_deferred = false;
export function flush_eager_effects() {
eager_effects_deferred = false;
const inspects = Array.from(inspect_effects);
const inspects = Array.from(eager_effects);
for (const effect of inspects) {
// Mark clean inspect-effects as maybe dirty and then check their dirtiness
@ -260,7 +260,7 @@ export function flush_inspect_effects() {
}
}
inspect_effects.clear();
eager_effects.clear();
}
/**
@ -320,8 +320,8 @@ function mark_reactions(signal, status) {
if (!runes && reaction === active_effect) continue;
// Inspect effects need to run immediately, so that the stack trace makes sense
if (DEV && (flags & INSPECT_EFFECT) !== 0) {
inspect_effects.add(reaction);
if (DEV && (flags & EAGER_EFFECT) !== 0) {
eager_effects.add(reaction);
continue;
}

Loading…
Cancel
Save