rename types

blockless
Rich Harris 10 months ago
parent c28534e3aa
commit 25dcfabcd8

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

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

@ -30,7 +30,7 @@ import {
* @param {V} value
*/
function create_computation_signal(flags, value) {
/** @type {import('../types.js').ComputationSignal<V>} */
/** @type {import('../types.js').Computation<V>} */
const signal = {
c: null,
d: null,
@ -55,8 +55,8 @@ function create_computation_signal(flags, value) {
}
/**
* @param {import('../types.js').ComputationSignal} target_signal
* @param {import('../types.js').ComputationSignal} ref_signal
* @param {import('../types.js').Computation} target_signal
* @param {import('../types.js').Computation} ref_signal
* @returns {void}
*/
export function push_reference(target_signal, ref_signal) {
@ -218,13 +218,13 @@ export function render_effect(fn, managed = false, sync = true) {
/**
* @template V
* @param {() => V} fn
* @returns {import('../types.js').ComputationSignal<V>}
* @returns {import('../types.js').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('../types.js').ComputationSignal<V>} */ (
const signal = /** @type {import('../types.js').Computation<V>} */ (
create_computation_signal(flags | CLEAN, UNINITIALIZED)
);
signal.i = fn;
@ -238,7 +238,7 @@ export function derived(fn) {
/**
* @template V
* @param {() => V} fn
* @returns {import('../types.js').ComputationSignal<V>}
* @returns {import('../types.js').Computation<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function derived_safe_equal(fn) {
@ -248,7 +248,7 @@ export function derived_safe_equal(fn) {
}
/**
* @param {import('../types.js').ComputationSignal} effect
* @param {import('../types.js').Computation} effect
* @param {() => void} done
*/
export function pause_effect(effect, done) {

@ -6,7 +6,7 @@ import { CLEAN, SOURCE } from '../constants.js';
/**
* @template V
* @param {V} initial_value
* @returns {import('../types.js').SourceSignal<V>}
* @returns {import('../types.js').Source<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function source(initial_value) {
@ -16,7 +16,7 @@ export function source(initial_value) {
/**
* @template V
* @param {V} initial_value
* @returns {import('../types.js').SourceSignal<V>}
* @returns {import('../types.js').Source<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function mutable_source(initial_value) {
@ -36,7 +36,7 @@ export function mutable_source(initial_value) {
* @template V
* @param {import('../types.js').SignalFlags} flags
* @param {V} value
* @returns {import('../types.js').SourceSignal<V> | import('../types.js').SourceSignal<V> & import('../types.js').SourceSignalDebug}
* @returns {import('../types.js').Source<V> | import('../types.js').Source<V> & import('../types.js').SourceDebug}
*/
function create_source_signal(flags, value) {
if (DEV) {

@ -50,7 +50,7 @@ export function store_get(store, store_name, stores) {
/**
* @template V
* @param {import('../types.js').Store<V> | null | undefined} store
* @param {import('../types.js').SourceSignal<V>} source
* @param {import('../types.js').Source<V>} source
*/
function connect_store_to_signal(store, source) {
if (store == null) {

@ -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').ComputationSignal | undefined} */
/** @type {import('./types.js').Computation | undefined} */
let render;
let destroyed = false;
const effect = managed_effect(() => {

@ -54,7 +54,7 @@ let current_queued_effects = [];
let flush_count = 0;
// Handle signal reactivity tree dependencies and consumer
/** @type {null | import('./types.js').ComputationSignal} */
/** @type {null | import('./types.js').Computation} */
export let current_consumer = null;
/** @type {null | import('./types.js').EffectSignal} */
@ -161,7 +161,7 @@ function is_signal_dirty(signal) {
return true;
}
if ((flags & MAYBE_DIRTY) !== 0) {
const dependencies = /** @type {import('./types.js').ComputationSignal<V>} **/ (signal).d;
const dependencies = /** @type {import('./types.js').Computation<V>} **/ (signal).d;
if (dependencies !== null) {
const length = dependencies.length;
let i;
@ -174,10 +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').ComputationSignal<V>} **/ (dependency),
true
);
update_derived(/** @type {import('./types.js').Computation<V>} **/ (dependency), true);
// Might have been mutated from above get.
if ((signal.f & DIRTY) !== 0) {
return true;
@ -205,7 +202,7 @@ function is_signal_dirty(signal) {
/**
* @template V
* @param {import('./types.js').ComputationSignal<V>} signal
* @param {import('./types.js').Computation<V>} signal
* @returns {V}
*/
function execute_signal_fn(signal) {
@ -311,7 +308,7 @@ function execute_signal_fn(signal) {
/**
* @template V
* @param {import('./types.js').ComputationSignal<V>} signal
* @param {import('./types.js').Computation<V>} signal
* @param {import('./types.js').Signal<V>} dependency
* @returns {void}
*/
@ -334,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').ComputationSignal<V>} **/ (dependency), 0);
remove_consumers(/** @type {import('./types.js').Computation<V>} **/ (dependency), 0);
}
}
/**
* @template V
* @param {import('./types.js').ComputationSignal<V>} signal
* @param {import('./types.js').Computation<V>} signal
* @param {number} start_index
* @returns {void}
*/
@ -361,7 +358,7 @@ function remove_consumers(signal, start_index) {
/**
* @template V
* @param {import('./types.js').ComputationSignal<V>} signal
* @param {import('./types.js').Computation<V>} signal
* @returns {void}
*/
function destroy_references(signal) {
@ -654,7 +651,7 @@ export async function tick() {
/**
* @template V
* @param {import('./types.js').ComputationSignal<V>} signal
* @param {import('./types.js').Computation<V>} signal
* @param {boolean} force_schedule
* @returns {void}
*/
@ -741,10 +738,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').ComputationSignal<V>} **/ (signal), false);
update_derived(/** @type {import('./types.js').Computation<V>} **/ (signal), false);
inspect_fn = previous_inspect_fn;
} else {
update_derived(/** @type {import('./types.js').ComputationSignal<V>} **/ (signal), false);
update_derived(/** @type {import('./types.js').Computation<V>} **/ (signal), false);
}
}
return signal.v;
@ -924,7 +921,7 @@ export function set_signal_value(signal, value) {
/**
* @template V
* @param {import('./types.js').ComputationSignal<V>} signal
* @param {import('./types.js').Computation<V>} signal
* @returns {void}
*/
export function destroy_signal(signal) {
@ -968,7 +965,7 @@ export function untrack(fn) {
/**
* @template V
* @param {import('./types.js').ComputationSignal<V>} signal
* @param {import('./types.js').Computation<V>} signal
* @param {() => void} destroy_fn
* @returns {void}
*/

@ -55,9 +55,9 @@ export type ComponentContext = {
// (effects and derived signals). Thus we can improve the memory profile at the slight cost
// of some runtime performance.
export type SourceSignal<V = unknown> = {
export type Source<V = unknown> = {
/** consumers: Signals that read from the current signal */
c: null | ComputationSignal[];
c: null | Computation[];
/** equals: For value equality */
e: null | EqualsFunctions;
/** flags: The types that the signal represent, as a bitwise value */
@ -68,14 +68,14 @@ export type SourceSignal<V = unknown> = {
w: number;
};
export type SourceSignalDebug = {
export type SourceDebug = {
/** This is DEV only */
inspect: Set<Function>;
};
export type ComputationSignal<V = unknown> = {
export type Computation<V = unknown> = {
/** consumers: Signals that read from the current signal */
c: null | ComputationSignal[];
c: null | Computation[];
/** context: The associated component if this signal is an effect/computed */
x: null | ComponentContext;
/** dependencies: Signals that this signal reads from */
@ -93,7 +93,7 @@ export type ComputationSignal<V = unknown> = {
| (() => void | (() => void))
| ((b: Block, s: Signal) => void | (() => void));
/** references: Anything that a signal owns */
r: null | ComputationSignal[];
r: null | Computation[];
/** 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 **/
@ -103,18 +103,18 @@ export type ComputationSignal<V = unknown> = {
parent: Signal | null;
};
export type BlockEffect<V = unknown> = ComputationSignal<V> & {
export type BlockEffect<V = unknown> = Computation<V> & {
in?: TransitionObject[];
out?: TransitionObject[];
dom?: TemplateNode | Array<TemplateNode>;
ran?: boolean;
};
export type Signal<V = unknown> = SourceSignal<V> | ComputationSignal<V>;
export type Signal<V = unknown> = Source<V> | Computation<V>;
export type SignalDebug<V = unknown> = SourceSignalDebug & Signal<V>;
export type SignalDebug<V = unknown> = SourceDebug & Signal<V>;
export type EffectSignal = ComputationSignal<null | (() => void)>;
export type EffectSignal = Computation<null | (() => void)>;
export type MaybeSignal<T = unknown> = T | Signal<T>;
@ -148,7 +148,7 @@ export type Transition = {
export type EachItemBlock = {
/** effect */
e: ComputationSignal;
e: Computation;
/** item */
v: any | Signal<any>;
/** index */
@ -219,9 +219,9 @@ export type TaskEntry = { c: TaskCallback; f: () => void };
export interface ProxyMetadata<T = Record<string | symbol, any>> {
/** A map of signals associated to the properties that are reactive */
s: Map<string | symbol, SourceSignal<any>>;
s: Map<string | symbol, Source<any>>;
/** A version counter, used within the proxy to signal changes in places where there's no other way to signal an update */
v: SourceSignal<number>;
v: Source<number>;
/** `true` if the proxified object is an array */
a: boolean;
/** Immutable: Whether to use a source or mutable source under the hood */

@ -7,7 +7,7 @@ import {
user_effect
} from '../../src/internal/client/reactivity/computations';
import { source } from '../../src/internal/client/reactivity/sources';
import type { ComputationSignal } from '../../src/internal/client/types';
import type { Computation } from '../../src/internal/client/types';
/**
* @param runes runes mode
@ -208,7 +208,7 @@ describe('signals', () => {
test('correctly cleanup onowned nested derived values', () => {
return () => {
const nested: ComputationSignal<string>[] = [];
const nested: Computation<string>[] = [];
const a = source(0);
const b = source(0);

Loading…
Cancel
Save