@ -127,8 +127,14 @@ export function set_untracked_writes(value) {
untracked _writes = value ;
}
/** @type {number} Used by sources and deriveds for handling updates to unowned deriveds it starts from 1 to differentiate between a created effect and a run one for tracing */
let current _version = 1 ;
/ * *
* @ type { number } Used by sources and deriveds for handling updates .
* Version starts from 1 so that unowned deriveds differentiate between a created effect and a run one for tracing
* * /
let write _version = 1 ;
/** @type {number} Used to version each read of a source of derived to avoid duplicating depedencies inside a reaction */
let read _version = 0 ;
// If we are working with a get() chain that has no active container,
// to prevent memory leaks, we skip adding the reaction.
@ -168,8 +174,8 @@ export function set_dev_current_component_function(fn) {
dev _current _component _function = fn ;
}
export function increment _ version( ) {
return ++ current _version ;
export function increment _ write_ version( ) {
return ++ write _version ;
}
/** @returns {boolean} */
@ -226,7 +232,7 @@ export function check_dirtiness(reaction) {
update _derived ( /** @type {Derived} */ ( dependency ) ) ;
}
if ( dependency . version > reaction . version ) {
if ( dependency . w v > reaction . w v) {
return true ;
}
}
@ -398,6 +404,7 @@ export function update_reaction(reaction) {
skip _reaction = ! is _flushing _effect && ( flags & UNOWNED ) !== 0 ;
derived _sources = null ;
component _context = reaction . ctx ;
read _version ++ ;
try {
var result = /** @type {Function} */ ( 0 , reaction . fn ) ( ) ;
@ -528,7 +535,7 @@ export function update_effect(effect) {
execute _effect _teardown ( effect ) ;
var teardown = update _reaction ( effect ) ;
effect . teardown = typeof teardown === 'function' ? teardown : null ;
effect . version = current _version ;
effect . wv = write _version ;
var deps = effect . deps ;
@ -540,7 +547,7 @@ export function update_effect(effect) {
for ( let i = 0 ; i < deps . length ; i ++ ) {
var dep = deps [ i ] ;
if ( dep . trace _need _increase ) {
dep . version = increment _version ( ) ;
dep . w v = increment _write _version ( ) ;
dep . trace _need _increase = undefined ;
dep . trace _v = undefined ;
}
@ -880,27 +887,29 @@ export function get(signal) {
e . state _unsafe _local _read ( ) ;
}
var deps = active _reaction . deps ;
if ( signal . rv < read _version ) {
signal . rv = read _version ;
// If the signal is accessing the same dependencies in the same
// order as it did last time, increment `skipped_deps`
// rather than updating `new_deps`, which creates GC cost
if ( new _deps === null && deps !== null && deps [ skipped _deps ] === signal ) {
skipped _deps ++ ;
} else if ( new _deps === null ) {
new _deps = [ signal ] ;
} else {
new _deps . push ( signal ) ;
}
// If the signal is accessing the same dependencies in the same
// order as it did last time, increment `skipped_deps`
// rather than updating `new_deps`, which creates GC cost
if ( new _deps === null && deps !== null && deps [ skipped _deps ] === signal ) {
skipped _deps ++ ;
} else if ( new _deps === null ) {
new _deps = [ signal ] ;
} else {
new _deps . push ( signal ) ;
}
if (
untracked _writes !== null &&
active _effect !== null &&
( active _effect . f & CLEAN ) !== 0 &&
( active _effect . f & BRANCH _EFFECT ) === 0 &&
untracked _writes . includes ( signal )
) {
set _signal _status ( active _effect , DIRTY ) ;
schedule _effect ( active _effect ) ;
if (
untracked _writes !== null &&
active _effect !== null &&
( active _effect . f & CLEAN ) !== 0 &&
( active _effect . f & BRANCH _EFFECT ) === 0 &&
untracked _writes . includes ( signal )
) {
set _signal _status ( active _effect , DIRTY ) ;
schedule _effect ( active _effect ) ;
}
}
} else if ( is _derived && /** @type {Derived} */ ( signal ) . deps === null ) {
var derived = /** @type {Derived} */ ( signal ) ;