@ -10,7 +10,7 @@ import { current_block, execute_effect } from '../../runtime.js';
import { destroy _effect , render _effect } from '../../reactivity/effects.js' ;
import { trigger _transitions } from '../elements/transitions.js' ;
/** @returns {import(' ../../types.js ').IfBlock} */
/** @returns {import(' #client ').IfBlock} */
function create _if _block ( ) {
return {
// alternate transitions
@ -26,7 +26,7 @@ function create_if_block() {
// effect
e : null ,
// parent
p : /** @type {import(' ../../types.js ').Block} */ ( current _block ) ,
p : /** @type {import(' #client ').Block} */ ( current _block ) ,
// transition
r : null ,
// type
@ -45,34 +45,48 @@ function create_if_block() {
* /
export function if _block ( anchor _node , condition _fn , consequent _fn , alternate _fn ) {
const block = create _if _block ( ) ;
hydrate _block _anchor ( anchor _node ) ;
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false ;
/** @type {null | import(' ../../types.js').TemplateNode | Array<import('../../types.js ').TemplateNode>} */
/** @type {null | import(' #client').TemplateNode | Array<import('#client ').TemplateNode>} */
let consequent _dom = null ;
/** @type {null | import('../../types.js').TemplateNode | Array<import('../../types.js').TemplateNode>} */
/** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
let alternate _dom = null ;
let has _mounted = false ;
/ * *
* @ type { import ( ' ../../types.js ') . Effect | null }
* @ type { import ( ' #client ') . Effect | null }
* /
let current _branch _effect = null ;
const if _effect = render _effect (
( ) => {
/** @type {import('#client').Effect} */
let consequent _effect ;
/** @type {import('#client').Effect} */
let alternate _effect ;
const if _effect = render _effect ( ( ) => {
const result = ! ! condition _fn ( ) ;
if ( block . v !== result || ! has _mounted ) {
block . v = result ;
if ( has _mounted ) {
const consequent _transitions = block . c ;
const alternate _transitions = block . a ;
if ( result ) {
if ( alternate _transitions === null || alternate _transitions . size === 0 ) {
execute _effect ( alternate _effect ) ;
} else {
trigger _transitions ( alternate _transitions , 'out' ) ;
}
if ( consequent _transitions === null || consequent _transitions . size === 0 ) {
execute _effect ( consequent _effect ) ;
} else {
@ -84,6 +98,7 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
} else {
trigger _transitions ( consequent _transitions , 'out' ) ;
}
if ( alternate _transitions === null || alternate _transitions . size === 0 ) {
execute _effect ( alternate _effect ) ;
} else {
@ -92,6 +107,7 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
}
} else if ( hydrating ) {
const comment _text = /** @type {Comment} */ ( current _hydration _fragment ? . [ 0 ] ) ? . data ;
if (
! comment _text ||
( comment _text === 'ssr:if:true' && ! result ) ||
@ -107,23 +123,20 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
current _hydration _fragment . shift ( ) ;
}
}
has _mounted = true ;
}
} ,
block ,
false
) ;
// Managed effect
const consequent _effect = render _effect (
(
/** @type {any} */ _ ,
/** @type {import('../../types.js').Effect | null} */ consequent _effect
) => {
// create these here so they have the correct parent/child relationship
consequent _effect ? ? = render _effect (
( /** @type {any} */ _ , /** @type {import('#client').Effect | null} */ consequent _effect ) => {
const result = block . v ;
if ( ! result && consequent _dom !== null ) {
remove ( consequent _dom ) ;
consequent _dom = null ;
}
if ( result && current _branch _effect !== consequent _effect ) {
consequent _fn ( anchor _node ) ;
if ( mismatch && current _branch _effect === null ) {
@ -133,31 +146,33 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
current _branch _effect = consequent _effect ;
consequent _dom = block . d ;
}
block . d = null ;
} ,
block ,
true
) ;
block . ce = consequent _effect ;
// Managed effect
const alternate _effect = render _effect (
(
/** @type {any} */ _ ,
/** @type {import('../../types.js').Effect | null} */ alternate _effect
) => {
alternate _effect ? ? = render _effect (
( /** @type {any} */ _ , /** @type {import('#client').Effect | null} */ alternate _effect ) => {
const result = block . v ;
if ( result && alternate _dom !== null ) {
remove ( alternate _dom ) ;
alternate _dom = null ;
}
if ( ! result && current _branch _effect !== alternate _effect ) {
if ( alternate _fn !== null ) {
alternate _fn ( anchor _node ) ;
}
if ( mismatch && current _branch _effect === null ) {
// Set fragment so that Svelte continues to operate in hydration mode
set _current _hydration _fragment ( [ ] ) ;
}
current _branch _effect = alternate _effect ;
alternate _dom = block . d ;
}
@ -167,15 +182,20 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
true
) ;
block . ae = alternate _effect ;
} , block ) ;
if _effect . ondestroy = ( ) => {
if ( consequent _dom !== null ) {
remove ( consequent _dom ) ;
}
if ( alternate _dom !== null ) {
remove ( alternate _dom ) ;
}
destroy _effect ( consequent _effect ) ;
destroy _effect ( alternate _effect ) ;
} ;
block . e = if _effect ;
}