tidy up types a bit

blockless
Rich Harris 10 months ago
parent c6a2e543e9
commit b81a1fb7a2

@ -25,13 +25,13 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
/** @type {any} */
let input;
/** @type {import('../../reactivity/types.js').EffectSignal | null} */
/** @type {import('#client').Effect | null} */
let pending_effect;
/** @type {import('../../reactivity/types.js').EffectSignal | null} */
/** @type {import('#client').Effect | null} */
let then_effect;
/** @type {import('../../reactivity/types.js').EffectSignal | null} */
/** @type {import('#client').Effect | null} */
let catch_effect;
const branch = render_effect(() => {

@ -315,10 +315,10 @@ export function each_indexed(anchor_node, collection, flags, render_fn, fallback
let length = 0;
/** @type {Array<import('#client').Computation | null>} */
/** @type {Array<import('#client').Effect | null>} */
let effects = [];
/** @type {import('#client').Computation | null} */
/** @type {import('#client').Effect | null} */
let alternate;
function truncate() {

@ -21,10 +21,10 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false;
/** @type {import('#client').EffectSignal | null} */
/** @type {import('#client').Effect | null} */
let consequent_effect;
/** @type {import('#client').EffectSignal | null} */
/** @type {import('#client').Effect | null} */
let alternate_effect;
/** @type {boolean | null} */

@ -16,7 +16,7 @@ export function key_block(anchor_node, get_key, render_fn) {
/** @type {V | typeof UNINITIALIZED} */
let key = UNINITIALIZED;
/** @type {import('#client').EffectSignal | null} */
/** @type {import('#client').Effect | null} */
let effect;
render_effect(() => {

@ -9,7 +9,7 @@ import { untrack } from '../../runtime.js';
* @returns {void}
*/
export function snippet_effect(get_snippet, node, ...args) {
/** @type {import('#client').EffectSignal | null} */
/** @type {import('#client').Effect | null} */
let effect;
render_effect(() => {

@ -15,7 +15,7 @@ export function component(anchor_node, component_fn, render_fn) {
/** @type {C | null} */
let Component = null;
/** @type {import('#client').Computation | null} */
/** @type {import('#client').Effect | null} */
let effect = null;
render_effect(() => {

@ -23,13 +23,13 @@ export function element(anchor_node, get_tag, is_svg, render_fn) {
/** @type {string} */
let tag;
/** @type {import('#client').BlockEffect | null} */
/** @type {import('#client').Effect | null} */
let block;
/** @type {Element | null} */
let element;
let element = null;
/** @type {import('#client').EffectSignal} */
/** @type {import('#client').Effect} */
let branch;
branch = render_effect(() => {

@ -150,7 +150,7 @@ export function unstate(value) {
}
/**
* @param {import('./types.js').Signal<number>} signal
* @param {import('./types.js').ValueSignal<number>} signal
* @param {1 | -1} [d]
*/
function update_version(signal, d = 1) {

@ -1,13 +1,11 @@
import { DEV } from 'esm-env';
import {
current_component_context,
current_consumer,
current_effect,
execute_effect,
flush_local_render_effects,
schedule_effect
} from '../runtime.js';
import { default_equals, safe_equal } from './equality.js';
import { remove } from '../reconciler.js';
import {
DIRTY,
@ -16,9 +14,6 @@ import {
EFFECT,
PRE_EFFECT,
DERIVED,
UNOWNED,
CLEAN,
UNINITIALIZED,
INERT,
ROOT_EFFECT,
DESTROYED
@ -30,7 +25,7 @@ import {
* @param {V} value
*/
function create_computation_signal(flags, value) {
/** @type {import('#client').Computation<V>} */
/** @type {import('#client').Effect} */
const signal = {
c: null,
d: null,
@ -43,6 +38,10 @@ function create_computation_signal(flags, value) {
w: 0,
x: null,
y: null,
in: null,
out: null,
dom: null,
ran: false,
parent: current_effect
};
@ -55,8 +54,8 @@ function create_computation_signal(flags, value) {
}
/**
* @param {import('#client').Computation} target_signal
* @param {import('#client').Computation} ref_signal
* @param {import('#client').Reaction} target_signal
* @param {import('#client').Reaction} ref_signal
* @returns {void}
*/
export function push_reference(target_signal, ref_signal) {
@ -73,7 +72,7 @@ export function push_reference(target_signal, ref_signal) {
* @param {(() => void | (() => void))} fn
* @param {boolean} sync
* @param {boolean} schedule
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
function internal_create_effect(type, fn, sync, schedule) {
const signal = create_computation_signal(type | DIRTY, null);
@ -99,7 +98,7 @@ export function effect_active() {
/**
* Internal representation of `$effect(...)`
* @param {() => void | (() => void)} fn
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
export function user_effect(fn) {
if (current_effect === null) {
@ -138,7 +137,7 @@ export function user_root_effect(fn) {
/**
* @param {() => void | (() => void)} fn
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
export function effect(fn) {
return internal_create_effect(EFFECT, fn, false, true);
@ -146,7 +145,7 @@ export function effect(fn) {
/**
* @param {() => void | (() => void)} fn
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
export function managed_effect(fn) {
return internal_create_effect(EFFECT | MANAGED, fn, false, true);
@ -155,7 +154,7 @@ export function managed_effect(fn) {
/**
* @param {() => void | (() => void)} fn
* @param {boolean} sync
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
export function managed_pre_effect(fn, sync) {
return internal_create_effect(PRE_EFFECT | MANAGED, fn, sync, true);
@ -164,7 +163,7 @@ export function managed_pre_effect(fn, sync) {
/**
* Internal representation of `$effect.pre(...)`
* @param {() => void | (() => void)} fn
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
export function pre_effect(fn) {
if (current_effect === null) {
@ -193,7 +192,7 @@ export function pre_effect(fn) {
* bindings which are in later effects. However, we don't use a pre_effect directly as we don't want to flush anything.
*
* @param {() => void | (() => void)} fn
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
export function invalidate_effect(fn) {
return internal_create_effect(PRE_EFFECT, fn, true, true);
@ -203,7 +202,7 @@ export function invalidate_effect(fn) {
* @param {() => void | (() => void)} fn
* @param {boolean} managed
* @param {boolean} sync
* @returns {import('#client').EffectSignal}
* @returns {import('#client').Effect}
*/
export function render_effect(fn, managed = false, sync = true) {
let flags = RENDER_EFFECT;
@ -214,39 +213,7 @@ export function render_effect(fn, managed = false, sync = true) {
}
/**
* @template V
* @param {() => V} fn
* @returns {import('#client').Computation<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function derived(fn) {
const is_unowned = current_effect === null;
const flags = is_unowned ? DERIVED | UNOWNED : DERIVED;
const signal = /** @type {import('#client').Computation<V>} */ (
create_computation_signal(flags | CLEAN, UNINITIALIZED)
);
signal.i = fn;
signal.e = default_equals;
if (current_consumer !== null) {
push_reference(current_consumer, signal);
}
return signal;
}
/**
* @template V
* @param {() => V} fn
* @returns {import('#client').Computation<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function derived_safe_equal(fn) {
const signal = derived(fn);
signal.e = safe_equal;
return signal;
}
/**
* @param {import('#client').Computation} effect
* @param {import('#client').Effect} effect
* @param {() => void} done
*/
export function pause_effect(effect, done) {
@ -275,7 +242,7 @@ export function pause_effect(effect, done) {
}
/**
* @param {import('#client').BlockEffect} effect
* @param {import('#client').Effect} effect
* @param {import('#client').Transition[]} transitions
* @param {boolean} local
*/
@ -297,13 +264,13 @@ function pause_children(effect, transitions, local) {
if (effect.r) {
for (const child of effect.r) {
pause_children(child, transitions, false);
pause_children(child, transitions, false); // TODO separate child effects from child deriveds
}
}
}
/**
* @param {import('#client').BlockEffect} effect TODO this isn't just block effects, it's deriveds etc too
* @param {import('#client').Effect} effect TODO this isn't just block effects, it's deriveds etc too
*/
export function destroy_effect(effect) {
if ((effect.f & DESTROYED) !== 0) return;
@ -326,19 +293,19 @@ export function destroy_effect(effect) {
}
/**
* @param {import('#client').BlockEffect} effect
* @param {import('#client').Effect} effect
*/
export function resume_effect(effect) {
resume_children(effect, true);
}
/**
* @param {import('#client').BlockEffect} effect
* @param {import('#client').Effect} effect
* @param {boolean} local
*/
function resume_children(effect, local) {
if ((effect.f & DERIVED) === 0 && (effect.f & MANAGED) === 0) {
execute_effect(/** @type {import('#client').EffectSignal} */ (effect));
execute_effect(/** @type {import('#client').Effect} */ (effect));
}
if (effect.r) {

@ -0,0 +1,56 @@
import { DEV } from 'esm-env';
import { CLEAN, DERIVED, UNINITIALIZED, UNOWNED } from '../constants.js';
import { current_consumer, current_effect } from '../runtime.js';
import { push_reference } from './computations.js';
import { default_equals, safe_equal } from './equality.js';
/**
* @template V
* @param {() => V} fn
* @returns {import('#client').Derived<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function derived(fn) {
const is_unowned = current_effect === null;
const flags = is_unowned ? DERIVED | UNOWNED : DERIVED;
/** @type {import('#client').Derived<V>} */
const signal = {
c: null,
d: null,
e: default_equals,
f: flags | CLEAN,
l: 0,
i: fn,
r: null,
// @ts-expect-error
v: UNINITIALIZED,
w: 0,
x: null,
y: null,
parent: current_effect
};
if (DEV) {
// @ts-expect-error
signal.inspect = new Set();
}
if (current_consumer !== null) {
push_reference(current_consumer, signal);
}
return signal;
}
/**
* @template V
* @param {() => V} fn
* @returns {import('#client').Derived<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function derived_safe_equal(fn) {
const signal = derived(fn);
signal.e = safe_equal;
return signal;
}

@ -12,7 +12,7 @@ export type EffectType = typeof EFFECT | typeof PRE_EFFECT | typeof RENDER_EFFEC
export type Source<V = unknown> = {
/** consumers: Signals that read from the current signal */
c: null | Computation[];
c: null | Reaction[];
/** equals: For value equality */
e: null | EqualsFunctions;
/** flags: The types that the signal represent, as a bitwise value */
@ -28,9 +28,9 @@ export type SourceDebug = {
inspect: Set<Function>;
};
export type Computation<V = unknown> = {
export interface Derived<V = unknown> {
/** consumers: Signals that read from the current signal */
c: null | Computation[];
c: null | Reaction[];
/** context: The associated component if this signal is an effect/computed */
x: null | ComponentContext;
/** dependencies: Signals that this signal reads from */
@ -44,25 +44,58 @@ export type Computation<V = unknown> = {
/** init: The function that we invoke for effects and computeds */
i: null | (() => V) | (() => void | (() => void)) | ((b: null, s: Signal) => void | (() => void));
/** references: Anything that a signal owns */
r: null | Computation[];
r: null | Reaction[];
/** value: The latest value for this signal, doubles as the teardown for effects */
v: V;
/** level: the depth from the root signal, used for ordering render/pre-effects topologically **/
l: number;
/** write version: used for unowned signals to track if their depdendencies are dirty or not **/
w: number;
parent: Signal | null;
};
}
export type BlockEffect<V = unknown> = Computation<V> & {
in?: Transition[];
out?: Transition[];
dom?: TemplateNode | Array<TemplateNode>;
ran?: boolean;
};
export interface Effect {
/** consumers: Signals that read from the current signal */
c: null | Reaction[];
/** context: The associated component if this signal is an effect/computed */
x: null | ComponentContext;
/** dependencies: Signals that this signal reads from */
d: null | Signal[];
/** destroy: Thing(s) that need destroying */
y: null | (() => void) | Array<() => void>;
/** equals: For value equality */
e: null | EqualsFunctions;
/** The types that the signal represent, as a bitwise value */
f: SignalFlags;
/** init: The function that we invoke for effects and computeds */
i: null | (() => void | (() => void)) | ((b: null, s: Signal) => void | (() => void));
/** references: Anything that a signal owns */
r: null | Reaction[];
/** value: The latest value for this signal, doubles as the teardown for effects */
v: () => void;
/** level: the depth from the root signal, used for ordering render/pre-effects topologically **/
l: number;
/** write version: used for unowned signals to track if their depdendencies are dirty or not **/
w: number;
export type Signal<V = unknown> = Source<V> | Computation<V>;
/** in transitions */
in: null | Transition[];
export type SignalDebug<V = unknown> = SourceDebug & Signal<V>;
/** out transitions */
out: null | Transition[];
/** DOM nodes belonging to this effect */
dom: null | TemplateNode | Array<TemplateNode>;
export type EffectSignal = Computation<null | (() => void)>;
/** Whether the effect ran or not */
ran: boolean;
parent: null | Effect;
}
export type Reaction = Derived | Effect;
export type ValueSignal<V> = Source<V> | Derived<V>;
export type Signal<V = unknown> = Source<V> | Reaction;
export type SignalDebug<V = unknown> = SourceDebug & Signal<V>;

@ -45,7 +45,6 @@ import {
render_effect,
effect,
managed_effect,
derived,
pre_effect,
user_effect,
destroy_effect
@ -70,6 +69,7 @@ import { run } from '../common.js';
import { bind_transition } from './transitions.js';
import { mutable_source, source } from './reactivity/sources.js';
import { safe_equal, safe_not_equal } from './reactivity/equality.js';
import { derived } from './reactivity/deriveds.js';
/** @type {Set<string>} */
const all_registered_events = new Set();
@ -262,13 +262,13 @@ export function comment(anchor) {
* @returns {void}
*/
function close_template(dom, is_fragment, anchor) {
const effect = /** @type {import('./types.js').BlockEffect} */ (current_effect);
const effect = /** @type {import('#client').Effect} */ (current_effect);
/** @type {import('./types.js').TemplateNode | Array<import('./types.js').TemplateNode>} */
/** @type {import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
const current = is_fragment
? is_array(dom)
? dom
: /** @type {import('./types.js').TemplateNode[]} */ (Array.from(dom.childNodes))
: /** @type {import('#client').TemplateNode[]} */ (Array.from(dom.childNodes))
: dom;
if (!hydrating && anchor !== null) {
insert(current, null, anchor);
@ -718,7 +718,7 @@ export function bind_playback_rate(media, get_value, update) {
// Needs to happen after the element is inserted into the dom, else playback will be set back to 1 by the browser.
// For hydration we could do it immediately but the additional code is not worth the lost microtask.
/** @type {import('./types.js').Computation | undefined} */
/** @type {import('#client').Reaction | undefined} */
let render;
let destroyed = false;
const effect = managed_effect(() => {
@ -1542,7 +1542,7 @@ export function stringify(value) {
/**
* @template P
* @param {HTMLElement} dom
* @param {() => import('./types.js').TransitionFn<P | undefined>} get_transition_fn
* @param {() => import('#client').TransitionFn<P | undefined>} get_transition_fn
* @param {(() => P) | null} props
* @param {any} global
* @returns {void}
@ -1554,7 +1554,7 @@ export function transition(dom, get_transition_fn, props, global = false) {
/**
* @template P
* @param {HTMLElement} dom
* @param {() => import('./types.js').TransitionFn<P | undefined>} get_transition_fn
* @param {() => import('#client').TransitionFn<P | undefined>} get_transition_fn
* @param {(() => P) | null} props
* @returns {void}
*/
@ -1565,7 +1565,7 @@ export function animate(dom, get_transition_fn, props) {
/**
* @template P
* @param {HTMLElement} dom
* @param {() => import('./types.js').TransitionFn<P | undefined>} get_transition_fn
* @param {() => import('#client').TransitionFn<P | undefined>} get_transition_fn
* @param {(() => P) | null} props
* @param {any} global
* @returns {void}
@ -1578,7 +1578,7 @@ export { in_fn as in };
/**
* @template P
* @param {HTMLElement} dom
* @param {() => import('./types.js').TransitionFn<P | undefined>} get_transition_fn
* @param {() => import('#client').TransitionFn<P | undefined>} get_transition_fn
* @param {(() => P) | null} props
* @param {any} global
* @returns {void}
@ -1590,12 +1590,12 @@ export function out(dom, get_transition_fn, props, global = false) {
/**
* @template P
* @param {Element} dom
* @param {(dom: Element, value?: P) => import('./types.js').ActionPayload<P>} action
* @param {(dom: Element, value?: P) => import('#client').ActionPayload<P>} action
* @param {() => P} [value_fn]
* @returns {void}
*/
export function action(dom, action, value_fn) {
/** @type {undefined | import('./types.js').ActionPayload<P>} */
/** @type {undefined | import('#client').ActionPayload<P>} */
let payload = undefined;
let needs_deep_read = false;
// Action could come from a prop, therefore could be a signal, therefore untrack
@ -2053,7 +2053,7 @@ const rest_props_handler = {
};
/**
* @param {import('./types.js').Signal<Record<string, unknown>> | Record<string, unknown>} props
* @param {import('#client').Source<Record<string, unknown>> | Record<string, unknown>} props
* @param {string[]} rest
* @returns {Record<string, unknown>}
*/
@ -2497,7 +2497,7 @@ export function prop(props, key, flags, initial) {
* Legacy-mode only: Call `onMount` callbacks and set up `beforeUpdate`/`afterUpdate` effects
*/
export function init() {
const context = /** @type {import('./types.js').ComponentContext} */ (current_component_context);
const context = /** @type {import('#client').ComponentContext} */ (current_component_context);
const callbacks = context.u;
if (!callbacks) return;
@ -2530,7 +2530,7 @@ export function init() {
/**
* Invoke the getter of all signals associated with a component
* so they can be registered to the effect this function is called in.
* @param {import('./types.js').ComponentContext} context
* @param {import('#client').ComponentContext} context
*/
function observe_all(context) {
if (context.d) {

@ -45,22 +45,22 @@ let is_inspecting_signal = false;
// Handle effect queues
/** @type {import('./types.js').EffectSignal[]} */
/** @type {import('./types.js').Effect[]} */
let current_queued_pre_and_render_effects = [];
/** @type {import('./types.js').EffectSignal[]} */
/** @type {import('./types.js').Effect[]} */
let current_queued_effects = [];
let flush_count = 0;
// Handle signal reactivity tree dependencies and consumer
/** @type {null | import('./types.js').Computation} */
/** @type {null | import('./types.js').Reaction} */
export let current_consumer = null;
/** @type {null | import('./types.js').EffectSignal} */
/** @type {null | import('./types.js').Effect} */
export let current_effect = null;
/** @param {null | import('./types.js').EffectSignal} effect */
/** @param {null | import('./types.js').Effect} effect */
export function set_current_effect(effect) {
current_effect = effect;
}
@ -161,7 +161,7 @@ function is_signal_dirty(signal) {
return true;
}
if ((flags & MAYBE_DIRTY) !== 0) {
const dependencies = /** @type {import('./types.js').Computation<V>} **/ (signal).d;
const dependencies = /** @type {import('./types.js').Reaction} **/ (signal).d;
if (dependencies !== null) {
const length = dependencies.length;
let i;
@ -174,7 +174,7 @@ function is_signal_dirty(signal) {
// The flags can be marked as dirty from the above is_signal_dirty call.
if ((dependency.f & DIRTY) !== 0) {
if ((dependency.f & DERIVED) !== 0) {
update_derived(/** @type {import('./types.js').Computation<V>} **/ (dependency), true);
update_derived(/** @type {import('./types.js').Reaction} **/ (dependency), true);
// Might have been mutated from above get.
if ((signal.f & DIRTY) !== 0) {
return true;
@ -202,7 +202,7 @@ function is_signal_dirty(signal) {
/**
* @template V
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Reaction} signal
* @returns {V}
*/
function execute_signal_fn(signal) {
@ -308,7 +308,7 @@ function execute_signal_fn(signal) {
/**
* @template V
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Derived<V>} signal
* @param {import('./types.js').Signal<V>} dependency
* @returns {void}
*/
@ -331,13 +331,13 @@ function remove_consumer(signal, dependency) {
if (consumers_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_consumers(/** @type {import('./types.js').Computation<V>} **/ (dependency), 0);
remove_consumers(/** @type {import('./types.js').Derived<V>} **/ (dependency), 0);
}
}
/**
* @template V
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Derived<V>} signal
* @param {number} start_index
* @returns {void}
*/
@ -358,7 +358,7 @@ function remove_consumers(signal, start_index) {
/**
* @template V
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Reaction} signal
* @returns {void}
*/
function destroy_references(signal) {
@ -373,7 +373,7 @@ function destroy_references(signal) {
}
/**
* @param {import('./types.js').EffectSignal} signal
* @param {import('./types.js').Effect} signal
* @returns {void}
*/
export function execute_effect(signal) {
@ -426,7 +426,7 @@ function infinite_loop_guard() {
}
/**
* @param {Array<import('./types.js').EffectSignal>} effects
* @param {Array<import('./types.js').Effect>} effects
* @returns {void}
*/
function flush_queued_effects(effects) {
@ -474,7 +474,7 @@ function process_microtask() {
}
/**
* @param {import('./types.js').EffectSignal} signal
* @param {import('./types.js').Effect} signal
* @param {boolean} sync
* @returns {void}
*/
@ -609,10 +609,10 @@ export function flush_sync(fn, flush_previous = true) {
try {
infinite_loop_guard();
/** @type {import('./types.js').EffectSignal[]} */
/** @type {import('./types.js').Effect[]} */
const pre_and_render_effects = [];
/** @type {import('./types.js').EffectSignal[]} */
/** @type {import('./types.js').Effect[]} */
const effects = [];
current_scheduler_mode = FLUSH_SYNC;
current_queued_pre_and_render_effects = pre_and_render_effects;
@ -651,7 +651,7 @@ export async function tick() {
/**
* @template V
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Reaction} signal
* @param {boolean} force_schedule
* @returns {void}
*/
@ -680,7 +680,7 @@ function update_derived(signal, force_schedule) {
/**
* @template V
* @param {import('./types.js').Signal<V>} signal
* @param {import('./types.js').ValueSignal<V>} signal
* @returns {V}
*/
export function get(signal) {
@ -739,10 +739,10 @@ export function get(signal) {
// we want to avoid tracking indirect dependencies
const previous_inspect_fn = inspect_fn;
inspect_fn = null;
update_derived(/** @type {import('./types.js').Computation<V>} **/ (signal), false);
update_derived(/** @type {import('./types.js').Reaction} **/ (signal), false);
inspect_fn = previous_inspect_fn;
} else {
update_derived(/** @type {import('./types.js').Computation<V>} **/ (signal), false);
update_derived(/** @type {import('./types.js').Reaction} **/ (signal), false);
}
}
return signal.v;
@ -840,7 +840,7 @@ function mark_signal_consumers(signal, to_status, force_schedule) {
const maybe_dirty = (flags & MAYBE_DIRTY) !== 0;
if ((flags & CLEAN) !== 0 || (maybe_dirty && unowned)) {
if ((consumer.f & IS_EFFECT) !== 0) {
schedule_effect(/** @type {import('./types.js').EffectSignal} */ (consumer), false);
schedule_effect(/** @type {import('./types.js').Effect} */ (consumer), false);
} else {
mark_signal_consumers(consumer, MAYBE_DIRTY, force_schedule);
}
@ -923,7 +923,7 @@ export function set_signal_value(signal, value) {
/**
* @template V
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Reaction} signal
* @returns {void}
*/
export function destroy_signal(signal) {
@ -967,7 +967,7 @@ export function untrack(fn) {
/**
* @template V
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Reaction} signal
* @param {() => void} destroy_fn
* @returns {void}
*/
@ -1035,7 +1035,7 @@ function get_parent_context(component_context) {
}
/**
* @param {import('./types.js').Signal<number>} signal
* @param {import('./types.js').ValueSignal<number>} signal
* @param {1 | -1} [d]
* @returns {number}
*/
@ -1057,7 +1057,7 @@ export function update_prop(fn, d = 1) {
}
/**
* @param {import('./types.js').Signal<number>} signal
* @param {import('./types.js').ValueSignal<number>} signal
* @param {1 | -1} [d]
* @returns {number}
*/

@ -248,7 +248,7 @@ const linear = (t) => t;
* @returns {void}
*/
export function bind_transition(element, get_fn, get_params, direction, global) {
const effect = /** @type {import('./types.js').BlockEffect} */ (current_effect);
const effect = /** @type {import('./types.js').Effect} */ (current_effect);
let p = direction === 'out' ? 1 : 0;
@ -358,7 +358,8 @@ export function bind_transition(element, get_fn, get_params, direction, global)
// if this is a local transition, we only want to run it if the parent (block) effect's
// parent (branch) effect is where the state change happened. we can determine that by
// looking at whether the branch effect is currently initializing
const should_run = run_transitions && (global || effect.parent.ran);
const should_run =
run_transitions && (global || /** @type {import('#client').Effect} */ (effect.parent).ran);
if (should_run) {
user_effect(() => {

@ -1,5 +1,5 @@
import { STATE_SYMBOL } from './constants.js';
import type { Computation, EffectSignal, Signal, Source } from './reactivity/types.js';
import type { Reaction, Effect, Signal, Source } from './reactivity/types.js';
export * from './reactivity/types.js';
@ -23,7 +23,7 @@ export type ComponentContext = {
/** exports (and props, if `accessors: true`) */
x: Record<string, any> | null;
/** effects */
e: null | Array<EffectSignal>;
e: null | Effect[];
/** mounted */
m: boolean;
/** parent */
@ -49,7 +49,7 @@ export type TemplateNode = Text | Element | Comment;
export type EachItemBlock = {
/** effect */
e: Computation;
e: Effect;
/** item */
v: any | Signal<any>;
/** index */

@ -31,6 +31,7 @@ export { component } from './client/dom/blocks/svelte-component.js';
export { element } from './client/dom/blocks/svelte-element.js';
export * from './client/dom/blocks/each.js';
export * from './client/reactivity/computations.js';
export * from './client/reactivity/deriveds.js';
export * from './client/reactivity/sources.js';
export * from './client/reactivity/equality.js';
export * from './client/reactivity/store.js';

@ -1,14 +1,14 @@
import { describe, assert, it } from 'vitest';
import * as $ from '../../src/internal/client/runtime';
import {
derived,
effect,
render_effect,
user_effect
} from '../../src/internal/client/reactivity/computations';
import { source } from '../../src/internal/client/reactivity/sources';
import type { Computation } from '../../src/internal/client/reactivity/types';
import type { Derived } from '../../src/internal/client/reactivity/types';
import { proxy } from '../../src/internal/client/proxy';
import { derived } from '../../src/internal/client/reactivity/deriveds';
/**
* @param runes runes mode
@ -209,7 +209,7 @@ describe('signals', () => {
test('correctly cleanup onowned nested derived values', () => {
return () => {
const nested: Computation<string>[] = [];
const nested: Derived<string>[] = [];
const a = source(0);
const b = source(0);

Loading…
Cancel
Save