@ -48,40 +48,40 @@ let is_inspecting_signal = false;
// Handle effect queues
/** @type {import('./types.js').Effect Signal []} */
/** @type {import('./types.js').Effect []} */
let current _queued _pre _and _render _effects = [ ] ;
/** @type {import('./types.js').Effect Signal []} */
/** @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'). ComputationSignal } */
/** @type {null | import('./types.js'). Reaction } */
export let current _consumer = null ;
/** @type {null | import('./types.js').Effect Signal } */
/** @type {null | import('./types.js').Effect } */
export let current _effect = null ;
/** @type {null | import('./types.js'). Signal []} */
/** @type {null | import('./types.js'). Value []} */
export 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' ) . S ignal [ ] }
* @ type { null | import ( './types.js' ) . S ource [ ] }
* /
export let current _untracked _writes = null ;
/** @param {null | import('./types.js').S ignal []} value */
/** @param {null | import('./types.js').S ource []} value */
export function set _current _untracked _writes ( value ) {
current _untracked _writes = value ;
}
/** @type {null | import('./types.js'). Signal Debug} */
/** @type {null | import('./types.js'). Value Debug} */
export let last _inspected _signal = null ;
/** @param {null | import('./types.js'). Signal Debug} signal */
/** @param {null | import('./types.js'). Value Debug} signal */
export function set _last _inspected _signal ( signal ) {
last _inspected _signal = signal ;
}
@ -105,7 +105,7 @@ let captured_signals = new Set();
/** @type {Function | null} */
export let inspect _fn = null ;
/** @type {Array<import('./types.js'). Signal Debug>} */
/** @type {Array<import('./types.js'). Value Debug>} */
let inspect _captured _signals = [ ] ;
// Handle rendering tree blocks and anchors
@ -160,8 +160,7 @@ export function batch_inspect(target, prop, receiver) {
}
/ * *
* @ template V
* @ param { import ( './types.js' ) . Signal < V > } signal
* @ param { import ( './types.js' ) . Signal } signal
* @ returns { boolean }
* /
function is _signal _dirty ( signal ) {
@ -170,7 +169,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'). Reaction } **/ ( signal ) . d ;
if ( dependencies !== null ) {
const length = dependencies . length ;
let i ;
@ -183,10 +182,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').Derived} **/ ( dependency ) , true ) ;
// Might have been mutated from above get.
if ( ( signal . f & DIRTY ) !== 0 ) {
return true ;
@ -214,7 +210,7 @@ function is_signal_dirty(signal) {
/ * *
* @ template V
* @ param { import ( './types.js' ) . ComputationSignal< V > } signal
* @ param { import ( './types.js' ) . Reaction } signal
* @ returns { V }
* /
function execute _signal _fn ( signal ) {
@ -229,7 +225,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('./types.js'). Value []} */ ( null ) ;
current _dependencies _index = 0 ;
current _untracked _writes = null ;
current _consumer = signal ;
@ -251,7 +247,7 @@ function execute_signal_fn(signal) {
} else {
res = /** @type {() => V} */ ( init ) ( ) ;
}
let dependencies = /** @type {import('./types.js'). Signal <unknown>[]} **/ ( signal . d ) ;
let dependencies = /** @type {import('./types.js'). Value <unknown>[]} **/ ( signal . d ) ;
if ( current _dependencies !== null ) {
let i ;
if ( dependencies !== null ) {
@ -286,7 +282,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('./types.js'). Value <V>[]} **/ (
dependencies = current _dependencies
) ;
}
@ -326,8 +322,8 @@ function execute_signal_fn(signal) {
/ * *
* @ template V
* @ param { import ( './types.js' ) . ComputationSignal< V > } signal
* @ param { import ( './types.js' ) . Signal < V > } dependency
* @ param { import ( './types.js' ) . Reaction } signal
* @ param { import ( './types.js' ) . Value < V > } dependency
* @ returns { void }
* /
function remove _consumer ( signal , dependency ) {
@ -349,13 +345,12 @@ 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'). Reaction } **/ ( dependency ) , 0 ) ;
}
}
/ * *
* @ template V
* @ param { import ( './types.js' ) . ComputationSignal < V > } signal
* @ param { import ( './types.js' ) . Reaction } signal
* @ param { number } start _index
* @ returns { void }
* /
@ -375,8 +370,7 @@ function remove_consumers(signal, start_index) {
}
/ * *
* @ template V
* @ param { import ( './types.js' ) . ComputationSignal < V > } signal
* @ param { import ( './types.js' ) . Reaction } signal
* @ returns { void }
* /
function destroy _references ( signal ) {
@ -405,7 +399,7 @@ function report_error(block, error) {
}
/ * *
* @ param { import ( './types.js' ) . Effect Signal } signal
* @ param { import ( './types.js' ) . Effect } signal
* @ returns { void }
* /
export function execute _effect ( signal ) {
@ -460,7 +454,7 @@ function infinite_loop_guard() {
}
/ * *
* @ param { Array < import ( './types.js' ) . Effect Signal > } effects
* @ param { Array < import ( './types.js' ) . Effect > } effects
* @ returns { void }
* /
function flush _queued _effects ( effects ) {
@ -508,7 +502,7 @@ function process_microtask() {
}
/ * *
* @ param { import ( './types.js' ) . Effect Signal } signal
* @ param { import ( './types.js' ) . Effect } signal
* @ param { boolean } sync
* @ returns { void }
* /
@ -640,10 +634,10 @@ export function flush_sync(fn, flush_previous = true) {
try {
infinite _loop _guard ( ) ;
/** @type {import('./types.js').Effect Signal []} */
/** @type {import('./types.js').Effect []} */
const pre _and _render _effects = [ ] ;
/** @type {import('./types.js').Effect Signal []} */
/** @type {import('./types.js').Effect []} */
const effects = [ ] ;
current _scheduler _mode = FLUSH _SYNC ;
current _queued _pre _and _render _effects = pre _and _render _effects ;
@ -681,8 +675,7 @@ export async function tick() {
}
/ * *
* @ template V
* @ param { import ( './types.js' ) . ComputationSignal < V > } signal
* @ param { import ( './types.js' ) . Derived } signal
* @ param { boolean } force _schedule
* @ returns { void }
* /
@ -704,20 +697,20 @@ function update_derived(signal, force_schedule) {
// @ts-expect-error
if ( DEV && signal . inspect && force _schedule ) {
for ( const fn of /** @type {import('./types.js'). Signal Debug} */ ( signal ) . inspect ) fn ( ) ;
for ( const fn of /** @type {import('./types.js'). Value Debug} */ ( signal ) . inspect ) fn ( ) ;
}
}
}
/ * *
* @ template V
* @ param { import ( './types.js' ) . Signal < V > } signal
* @ param { import ( './types.js' ) . Value < V > } signal
* @ returns { V }
* /
export function get ( signal ) {
// @ts-expect-error
if ( DEV && signal . inspect && inspect _fn ) {
/** @type {import('./types.js'). Signal Debug} */ ( signal ) . inspect . add ( inspect _fn ) ;
/** @type {import('./types.js'). Value Debug} */ ( signal ) . inspect . add ( inspect _fn ) ;
// @ts-expect-error
inspect _captured _signals . push ( signal ) ;
}
@ -770,10 +763,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'). Derived } **/ ( signal ) , false ) ;
inspect _fn = previous _inspect _fn ;
} else {
update _derived ( /** @type {import('./types.js'). ComputationSignal<V> } **/ ( signal ) , false ) ;
update _derived ( /** @type {import('./types.js'). Derived } **/ ( signal ) , false ) ;
}
}
return signal . v ;
@ -808,7 +801,7 @@ export function invalidate_inner_signals(fn) {
}
/ * *
* @ param { import ( './types.js' ) . ComputationSignal } signal
* @ param { import ( './types.js' ) . Reaction } signal
* @ param { boolean } inert
* @ param { Set < import ( './types.js' ) . Block > } [ visited _blocks ]
* @ returns { void }
@ -827,7 +820,7 @@ function mark_subtree_children_inert(signal, inert, visited_blocks) {
}
/ * *
* @ param { import ( './types.js' ) . ComputationSignal } signal
* @ param { import ( './types.js' ) . Reaction } signal
* @ param { boolean } inert
* @ param { Set < import ( './types.js' ) . Block > } [ visited _blocks ]
* @ returns { void }
@ -838,7 +831,7 @@ export function mark_subtree_inert(signal, inert, visited_blocks = new Set()) {
if ( is _already _inert !== inert ) {
signal . f ^= INERT ;
if ( ! inert && ( flags & IS _EFFECT ) !== 0 && ( flags & CLEAN ) === 0 ) {
schedule _effect ( /** @type {import('./types.js').Effect Signal } */ ( signal ) , false ) ;
schedule _effect ( /** @type {import('./types.js').Effect } */ ( signal ) , false ) ;
}
// Nested if block effects
const block = signal . b ;
@ -901,7 +894,7 @@ export 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 Signal } */ ( consumer ) , false ) ;
schedule _effect ( /** @type {import('./types.js').Effect } */ ( consumer ) , false ) ;
} else {
mark _signal _consumers ( consumer , MAYBE _DIRTY , force _schedule ) ;
}
@ -911,8 +904,7 @@ export function mark_signal_consumers(signal, to_status, force_schedule) {
}
/ * *
* @ template V
* @ param { import ( './types.js' ) . ComputationSignal < V > } signal
* @ param { import ( './types.js' ) . Reaction } signal
* @ returns { void }
* /
export function destroy _signal ( signal ) {
@ -954,8 +946,7 @@ export function untrack(fn) {
}
/ * *
* @ template V
* @ param { import ( './types.js' ) . ComputationSignal < V > } signal
* @ param { import ( './types.js' ) . Reaction } signal
* @ param { ( ) => void } destroy _fn
* @ returns { void }
* /
@ -1104,7 +1095,7 @@ function get_parent_context(component_context) {
}
/ * *
* @ param { import ( './types.js' ) . Signal < number > } signal
* @ param { import ( './types.js' ) . Value < number > } signal
* @ param { 1 | - 1 } [ d ]
* @ returns { number }
* /
@ -1115,7 +1106,7 @@ export function update(signal, d = 1) {
}
/ * *
* @ param { import ( './types.js' ) . Signal < number > } signal
* @ param { import ( './types.js' ) . Value < number > } signal
* @ param { 1 | - 1 } [ d ]
* @ returns { number }
* /