more tidying up

blockless
Rich Harris 3 years ago
parent 752c42a99c
commit e064363529

@ -1,6 +1,6 @@
import { createClassComponent } from '../../legacy/legacy-client.js';
import { destroy_signal } from './runtime.js';
import { render_effect } from './reactivity/computations.js';
import { render_effect } from './reactivity/effects.js';
import { open, close } from './render.js';
import { define_property } from './utils.js';

@ -5,7 +5,7 @@ import {
set_current_component_context,
set_current_effect
} from '../../runtime.js';
import { pause_effect, render_effect, resume_effect } from '../../reactivity/computations.js';
import { pause_effect, render_effect, resume_effect } from '../../reactivity/effects.js';
import { BRANCH_EFFECT } from '../../constants.js';
/**

@ -1,7 +1,7 @@
import { namespace_svg } from '../../../../constants.js';
import { current_hydration_fragment, hydrate_block_anchor, hydrating } from '../../hydration.js';
import { empty } from '../../operations.js';
import { render_effect } from '../../reactivity/computations.js';
import { render_effect } from '../../reactivity/effects.js';
import { insert } from '../../reconciler.js';
/**

@ -21,7 +21,7 @@ import {
pause_effect,
render_effect,
resume_effect
} from '../../reactivity/computations.js';
} from '../../reactivity/effects.js';
import { source, mutable_source } from '../../reactivity/sources.js';
import { is_array } from '../../utils.js';
import { BRANCH_EFFECT } from '../../constants.js';

@ -1,4 +1,4 @@
import { render_effect } from '../../reactivity/computations.js';
import { render_effect } from '../../reactivity/effects.js';
import { reconcile_html, remove } from '../../reconciler.js';
/**

@ -5,7 +5,7 @@ import {
set_current_hydration_fragment
} from '../../hydration.js';
import { remove } from '../../reconciler.js';
import { pause_effect, render_effect, resume_effect } from '../../reactivity/computations.js';
import { pause_effect, render_effect, resume_effect } from '../../reactivity/effects.js';
import { BRANCH_EFFECT } from '../../constants.js';
/**

@ -1,6 +1,6 @@
import { UNINITIALIZED, BRANCH_EFFECT } from '../../constants.js';
import { hydrate_block_anchor } from '../../hydration.js';
import { pause_effect, render_effect } from '../../reactivity/computations.js';
import { pause_effect, render_effect } from '../../reactivity/effects.js';
import { noop } from '../../../common.js';
/**

@ -1,5 +1,5 @@
import { noop } from '../../../common.js';
import { destroy_effect, pause_effect, render_effect } from '../../reactivity/computations.js';
import { destroy_effect, pause_effect, render_effect } from '../../reactivity/effects.js';
import { untrack } from '../../runtime.js';
/**

@ -1,5 +1,5 @@
import { hydrate_block_anchor } from '../../hydration.js';
import { pause_effect, render_effect } from '../../reactivity/computations.js';
import { pause_effect, render_effect } from '../../reactivity/effects.js';
/**
* @template {Record<string, any>} P

@ -8,7 +8,7 @@ import {
pause_effect,
render_effect,
resume_effect
} from '../../reactivity/computations.js';
} from '../../reactivity/effects.js';
/**
* @param {Comment} anchor_node

@ -8,7 +8,7 @@ import {
untrack,
set_signal_value
} from './runtime.js';
import { effect_active } from './reactivity/computations.js';
import { effect_active } from './reactivity/effects.js';
import {
array_prototype,
define_property,

@ -20,14 +20,12 @@ export function derived(fn) {
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
};

@ -2,7 +2,7 @@ import { subscribe_to_store } from '../../../store/utils.js';
import { noop } from '../../common.js';
import { UNINITIALIZED } from '../constants.js';
import { get, set, set_ignore_mutation_validation, untrack } from '../runtime.js';
import { user_effect } from './computations.js';
import { user_effect } from './effects.js';
import { mutable_source } from './sources.js';
/**

@ -35,20 +35,16 @@ export interface Derived<V = unknown> {
x: null | ComponentContext;
/** dependencies: Signals that this signal reads from */
d: null | Signal<V>[];
/** 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 | (() => V) | (() => void | (() => void)) | ((b: null, s: Signal) => void | (() => void));
i: () => V;
/** references: Anything that a signal owns */
r: null | Reaction[];
/** value: The latest value for this signal, doubles as the teardown for effects */
/** value: The latest value for this signal */
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;
}
@ -70,25 +66,21 @@ export interface Effect {
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;
/** teardown */
v: null | (() => 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;
/** in transitions */
in: null | Transition[];
/** out transitions */
out: null | Transition[];
/** DOM nodes belonging to this effect */
dom: null | TemplateNode | Array<TemplateNode>;
/** Whether the effect ran or not */
ran: boolean;
/** The parent effect */
parent: null | Effect;
}

@ -48,7 +48,7 @@ import {
pre_effect,
user_effect,
destroy_effect
} from './reactivity/computations.js';
} from './reactivity/effects.js';
import {
current_hydration_fragment,
get_hydration_fragment,

@ -9,7 +9,7 @@ import {
object_prototype
} from './utils.js';
import { unstate } from './proxy.js';
import { pre_effect } from './reactivity/computations.js';
import { pre_effect } from './reactivity/effects.js';
import {
EFFECT,
PRE_EFFECT,
@ -45,36 +45,36 @@ let is_inspecting_signal = false;
// Handle effect queues
/** @type {import('./types.js').Effect[]} */
/** @type {import('#client').Effect[]} */
let current_queued_pre_and_render_effects = [];
/** @type {import('./types.js').Effect[]} */
/** @type {import('#client').Effect[]} */
let current_queued_effects = [];
let flush_count = 0;
// Handle signal reactivity tree dependencies and consumer
/** @type {null | import('./types.js').Reaction} */
/** @type {null | import('#client').Reaction} */
export let current_consumer = null;
/** @type {null | import('./types.js').Effect} */
/** @type {null | import('#client').Effect} */
export let current_effect = null;
/** @param {null | import('./types.js').Effect} effect */
/** @param {null | import('#client').Effect} effect */
export function set_current_effect(effect) {
current_effect = effect;
}
/** @type {null | import('./types.js').Signal[]} */
/** @type {null | import('#client').Signal[]} */
let current_dependencies = null;
let current_dependencies_index = 0;
/**
* Tracks writes that the effect it's executed in doesn't listen to yet,
* so that the dependency can be added to the effect later on if it then reads it
* @type {null | import('./types.js').Signal[]}
* @type {null | import('#client').Signal[]}
*/
let current_untracked_writes = null;
/** @type {null | import('./types.js').SignalDebug} */
/** @type {null | import('#client').SignalDebug} */
let last_inspected_signal = null;
/** If `true`, `get`ting the signal should not register it as a dependency */
export let current_untracking = false;
@ -95,14 +95,14 @@ let captured_signals = new Set();
/** @type {Function | null} */
export let inspect_fn = null;
/** @type {Array<import('./types.js').SignalDebug>} */
/** @type {Array<import('#client').SignalDebug>} */
let inspect_captured_signals = [];
// Handling runtime component context
/** @type {import('./types.js').ComponentContext | null} */
/** @type {import('#client').ComponentContext | null} */
export let current_component_context = null;
/** @param {import('./types.js').ComponentContext | null} context */
/** @param {import('#client').ComponentContext | null} context */
export function set_current_component_context(context) {
current_component_context = context;
}
@ -110,7 +110,7 @@ export function set_current_component_context(context) {
export let updating_derived = false;
/**
* @param {null | import('./types.js').ComponentContext} context
* @param {null | import('#client').ComponentContext} context
* @returns {boolean}
*/
function is_runes(context) {
@ -119,7 +119,7 @@ function is_runes(context) {
}
/**
* @param {import('./types.js').ProxyStateObject} target
* @param {import('#client').ProxyStateObject} target
* @param {string | symbol} prop
* @param {any} receiver
*/
@ -152,7 +152,7 @@ export function batch_inspect(target, prop, receiver) {
/**
* @template V
* @param {import('./types.js').Signal<V>} signal
* @param {import('#client').Signal<V>} signal
* @returns {boolean}
*/
function is_signal_dirty(signal) {
@ -161,7 +161,7 @@ function is_signal_dirty(signal) {
return true;
}
if ((flags & MAYBE_DIRTY) !== 0) {
const dependencies = /** @type {import('./types.js').Reaction} **/ (signal).d;
const dependencies = /** @type {import('#client').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').Reaction} **/ (dependency), true);
update_derived(/** @type {import('#client').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').Reaction} signal
* @param {import('#client').Reaction} signal
* @returns {V}
*/
function execute_signal_fn(signal) {
@ -216,7 +216,7 @@ function execute_signal_fn(signal) {
const previous_skip_consumer = current_skip_consumer;
const is_render_effect = (flags & RENDER_EFFECT) !== 0;
const previous_untracking = current_untracking;
current_dependencies = /** @type {null | import('./types.js').Signal[]} */ (null);
current_dependencies = /** @type {null | import('#client').Signal[]} */ (null);
current_dependencies_index = 0;
current_untracked_writes = null;
current_consumer = signal;
@ -227,14 +227,14 @@ function execute_signal_fn(signal) {
try {
let res;
if (is_render_effect) {
res = /** @type {(block: null, signal: import('./types.js').Signal) => V} */ (init)(
res = /** @type {(block: null, signal: import('#client').Signal) => V} */ (init)(
null,
/** @type {import('./types.js').Signal} */ (signal)
/** @type {import('#client').Signal} */ (signal)
);
} else {
res = /** @type {() => V} */ (init)();
}
let dependencies = /** @type {import('./types.js').Signal<unknown>[]} **/ (signal.d);
let dependencies = /** @type {import('#client').Signal<unknown>[]} **/ (signal.d);
if (current_dependencies !== null) {
let i;
if (dependencies !== null) {
@ -269,7 +269,7 @@ function execute_signal_fn(signal) {
dependencies[current_dependencies_index + i] = current_dependencies[i];
}
} else {
signal.d = /** @type {import('./types.js').Signal<V>[]} **/ (
signal.d = /** @type {import('#client').Signal<V>[]} **/ (
dependencies = current_dependencies
);
}
@ -308,8 +308,8 @@ function execute_signal_fn(signal) {
/**
* @template V
* @param {import('./types.js').Derived<V>} signal
* @param {import('./types.js').Signal<V>} dependency
* @param {import('#client').Reaction} signal
* @param {import('#client').Signal<V>} dependency
* @returns {void}
*/
function remove_consumer(signal, dependency) {
@ -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').Derived<V>} **/ (dependency), 0);
remove_consumers(/** @type {import('#client').Derived<V>} **/ (dependency), 0);
}
}
/**
* @template V
* @param {import('./types.js').Derived<V>} signal
* @param {import('#client').Reaction} signal
* @param {number} start_index
* @returns {void}
*/
@ -358,7 +358,7 @@ function remove_consumers(signal, start_index) {
/**
* @template V
* @param {import('./types.js').Reaction} signal
* @param {import('#client').Reaction} signal
* @returns {void}
*/
function destroy_references(signal) {
@ -373,7 +373,7 @@ function destroy_references(signal) {
}
/**
* @param {import('./types.js').Effect} signal
* @param {import('#client').Effect} signal
* @returns {void}
*/
export function execute_effect(signal) {
@ -426,7 +426,7 @@ function infinite_loop_guard() {
}
/**
* @param {Array<import('./types.js').Effect>} effects
* @param {Array<import('#client').Effect>} effects
* @returns {void}
*/
function flush_queued_effects(effects) {
@ -474,7 +474,7 @@ function process_microtask() {
}
/**
* @param {import('./types.js').Effect} signal
* @param {import('#client').Effect} signal
* @param {boolean} sync
* @returns {void}
*/
@ -569,7 +569,7 @@ export function flush_local_render_effects() {
}
/**
* @param {null | import('./types.js').ComponentContext} context
* @param {null | import('#client').ComponentContext} context
* @returns {void}
*/
export function flush_local_pre_effects(context) {
@ -609,10 +609,10 @@ export function flush_sync(fn, flush_previous = true) {
try {
infinite_loop_guard();
/** @type {import('./types.js').Effect[]} */
/** @type {import('#client').Effect[]} */
const pre_and_render_effects = [];
/** @type {import('./types.js').Effect[]} */
/** @type {import('#client').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').Reaction} signal
* @param {import('#client').Reaction} signal
* @param {boolean} force_schedule
* @returns {void}
*/
@ -666,27 +666,27 @@ function update_derived(signal, force_schedule) {
? MAYBE_DIRTY
: CLEAN;
set_signal_status(signal, status);
const equals = /** @type {import('./types.js').EqualsFunctions} */ (signal.e);
const equals = /** @type {import('#client').EqualsFunctions} */ (signal.e);
if (!equals(value, signal.v)) {
signal.v = value;
mark_signal_consumers(signal, DIRTY, force_schedule);
// @ts-expect-error
if (DEV && signal.inspect && force_schedule) {
for (const fn of /** @type {import('./types.js').SignalDebug} */ (signal).inspect) fn();
for (const fn of /** @type {import('#client').SignalDebug} */ (signal).inspect) fn();
}
}
}
/**
* @template V
* @param {import('./types.js').ValueSignal<V>} signal
* @param {import('#client').ValueSignal<V>} signal
* @returns {V}
*/
export function get(signal) {
// @ts-expect-error
if (DEV && signal.inspect && inspect_fn) {
/** @type {import('./types.js').SignalDebug} */ (signal).inspect.add(inspect_fn);
/** @type {import('#client').SignalDebug} */ (signal).inspect.add(inspect_fn);
// @ts-expect-error
inspect_captured_signals.push(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').Reaction} **/ (signal), false);
update_derived(/** @type {import('#client').Reaction} **/ (signal), false);
inspect_fn = previous_inspect_fn;
} else {
update_derived(/** @type {import('./types.js').Reaction} **/ (signal), false);
update_derived(/** @type {import('#client').Reaction} **/ (signal), false);
}
}
return signal.v;
@ -750,7 +750,7 @@ export function get(signal) {
/**
* @template V
* @param {import('./types.js').Signal<V>} signal
* @param {import('#client').Signal<V>} signal
* @param {V} value
* @returns {V}
*/
@ -761,7 +761,7 @@ export function set(signal, value) {
/**
* @template V
* @param {import('./types.js').Signal<V>} signal
* @param {import('#client').Signal<V>} signal
* @param {V} value
* @returns {void}
*/
@ -799,7 +799,7 @@ export function invalidate_inner_signals(fn) {
/**
* @template V
* @param {import('./types.js').Signal<V>} source
* @param {import('#client').Signal<V>} source
* @param {V} value
*/
export function mutate(source, value) {
@ -812,7 +812,7 @@ export function mutate(source, value) {
/**
* @template V
* @param {import('./types.js').Signal<V>} signal
* @param {import('#client').Signal<V>} signal
* @param {number} to_status
* @param {boolean} force_schedule
* @returns {void}
@ -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').Effect} */ (consumer), false);
schedule_effect(/** @type {import('#client').Effect} */ (consumer), false);
} else {
mark_signal_consumers(consumer, MAYBE_DIRTY, force_schedule);
}
@ -851,7 +851,7 @@ function mark_signal_consumers(signal, to_status, force_schedule) {
/**
* @template V
* @param {import('./types.js').Signal<V>} signal
* @param {import('#client').Signal<V>} signal
* @param {V} value
* @returns {void}
*/
@ -874,7 +874,7 @@ export function set_signal_value(signal, value) {
}
if (
(signal.f & SOURCE) !== 0 &&
!(/** @type {import('./types.js').EqualsFunctions} */ (signal.e)(value, signal.v))
!(/** @type {import('#client').EqualsFunctions} */ (signal.e)(value, signal.v))
) {
signal.v = value;
// Increment write version so that unowned signals can properly track dirtyness
@ -913,9 +913,9 @@ export function set_signal_value(signal, value) {
// @ts-expect-error
if (DEV && signal.inspect) {
if (is_batching_effect) {
last_inspected_signal = /** @type {import('./types.js').SignalDebug} */ (signal);
last_inspected_signal = /** @type {import('#client').SignalDebug} */ (signal);
} else {
for (const fn of /** @type {import('./types.js').SignalDebug} */ (signal).inspect) fn();
for (const fn of /** @type {import('#client').SignalDebug} */ (signal).inspect) fn();
}
}
}
@ -923,7 +923,7 @@ export function set_signal_value(signal, value) {
/**
* @template V
* @param {import('./types.js').Reaction} signal
* @param {import('#client').Reaction} signal
* @returns {void}
*/
export function destroy_signal(signal) {
@ -967,7 +967,7 @@ export function untrack(fn) {
/**
* @template V
* @param {import('./types.js').Reaction} signal
* @param {import('#client').Effect} signal
* @param {() => void} destroy_fn
* @returns {void}
*/
@ -985,7 +985,7 @@ export function push_destroy_fn(signal, destroy_fn) {
const STATUS_MASK = ~(DIRTY | MAYBE_DIRTY | CLEAN);
/**
* @template V
* @param {import('./types.js').Signal<V>} signal
* @param {import('#client').Signal<V>} signal
* @param {number} status
* @returns {void}
*/
@ -995,14 +995,14 @@ function set_signal_status(signal, status) {
/**
* @template V
* @param {V | import('./types.js').Signal<V>} val
* @returns {val is import('./types.js').Signal<V>}
* @param {V | import('#client').Signal<V>} val
* @returns {val is import('#client').Signal<V>}
*/
export function is_signal(val) {
return (
typeof val === 'object' &&
val !== null &&
typeof (/** @type {import('./types.js').Signal<V>} */ (val).f) === 'number'
typeof (/** @type {import('#client').Signal<V>} */ (val).f) === 'number'
);
}
@ -1019,7 +1019,7 @@ export function get_or_init_context_map() {
}
/**
* @param {import('./types.js').ComponentContext} component_context
* @param {import('#client').ComponentContext} component_context
* @returns {Map<unknown, unknown> | null}
*/
function get_parent_context(component_context) {
@ -1035,7 +1035,7 @@ function get_parent_context(component_context) {
}
/**
* @param {import('./types.js').ValueSignal<number>} signal
* @param {import('#client').ValueSignal<number>} signal
* @param {1 | -1} [d]
* @returns {number}
*/
@ -1057,7 +1057,7 @@ export function update_prop(fn, d = 1) {
}
/**
* @param {import('./types.js').ValueSignal<number>} signal
* @param {import('#client').ValueSignal<number>} signal
* @param {1 | -1} [d]
* @returns {number}
*/

@ -1,6 +1,6 @@
import { noop } from '../common.js';
import { loop } from './loop.js';
import { user_effect } from './reactivity/computations.js';
import { user_effect } from './reactivity/effects.js';
import { run_transitions } from './render.js';
import { current_effect, untrack } from './runtime.js';
import { raf } from './timing.js';

@ -30,7 +30,7 @@ export { snippet_effect } from './client/dom/blocks/render-tag.js';
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/effects.js';
export * from './client/reactivity/deriveds.js';
export * from './client/reactivity/sources.js';
export * from './client/reactivity/equality.js';

@ -1,10 +1,6 @@
import { describe, assert, it } from 'vitest';
import * as $ from '../../src/internal/client/runtime';
import {
effect,
render_effect,
user_effect
} from '../../src/internal/client/reactivity/computations';
import { effect, render_effect, user_effect } from '../../src/internal/client/reactivity/effects';
import { source } from '../../src/internal/client/reactivity/sources';
import type { Derived } from '../../src/internal/client/reactivity/types';
import { proxy } from '../../src/internal/client/proxy';

Loading…
Cancel
Save