@ -3,7 +3,6 @@ import {
current _component _context ,
current _effect ,
current _reaction ,
current _untracking ,
destroy _effect _children ,
dev _current _component _function ,
execute _effect ,
@ -12,10 +11,10 @@ import {
is _flushing _effect ,
remove _reactions ,
schedule _effect ,
set _current _reaction ,
set _is _destroying _effect ,
set _is _flushing _effect ,
set _signal _status ,
set _untracking ,
untrack
} from '../runtime.js' ;
import {
@ -47,6 +46,10 @@ export function validate_effect(rune) {
e . effect _orphan ( rune ) ;
}
if ( current _reaction !== null && ( current _reaction . f & UNOWNED ) !== 0 ) {
e . effect _in _unowned _derived ( ) ;
}
if ( is _destroying _effect ) {
e . effect _in _teardown ( rune ) ;
}
@ -119,20 +122,15 @@ function create_effect(type, fn, sync) {
effect . dom === null &&
effect . teardown === null ;
if ( ! inert && current _reaction !== null && ! is _root ) {
var flags = current _reaction . f ;
if ( ( flags & DERIVED ) !== 0 ) {
if ( ( flags & UNOWNED ) !== 0 ) {
e . effect _in _unowned _derived ( ) ;
}
// If we are inside a derived, then we also need to attach the
// effect to the parent effect too.
if ( current _effect !== null ) {
push _effect ( effect , current _effect ) ;
}
if ( ! inert && ! is _root ) {
if ( current _effect !== null ) {
push _effect ( effect , current _effect ) ;
}
push _effect ( effect , current _reaction ) ;
// if we're in a derived, add the effect there too
if ( current _reaction !== null && ( current _reaction . f & DERIVED ) !== 0 ) {
push _effect ( effect , current _reaction ) ;
}
}
return effect ;
@ -143,18 +141,11 @@ function create_effect(type, fn, sync) {
* @ returns { boolean }
* /
export function effect _tracking ( ) {
if ( current _ untracking ) {
if ( current _ reaction === null ) {
return false ;
}
if ( current _reaction && ( current _reaction . f & DERIVED ) !== 0 ) {
return ( current _reaction . f & UNOWNED ) === 0 ;
}
if ( current _effect ) {
return ( current _effect . f & ( BRANCH _EFFECT | ROOT _EFFECT ) ) === 0 ;
}
return false ;
return ( current _reaction . f & UNOWNED ) === 0 ;
}
/ * *
@ -320,14 +311,14 @@ export function execute_effect_teardown(effect) {
var teardown = effect . teardown ;
if ( teardown !== null ) {
const previously _destroying _effect = is _destroying _effect ;
const previous _ untracking = current _untracking ;
const previous _ reaction = current _reaction ;
set _is _destroying _effect ( true ) ;
set _ untracking( true ) ;
set _ current_reaction ( null ) ;
try {
teardown . call ( null ) ;
} finally {
set _is _destroying _effect ( previously _destroying _effect ) ;
set _ untracking( previous _untracking ) ;
set _ current_reaction ( previous _reaction ) ;
}
}
}