@ -13,13 +13,11 @@ import { HYDRATION_START_ELSE } from '../../../../constants.js';
/ * *
* @ param { TemplateNode } node
* @ param { ( ) => boolean } get _condition
* @ param { ( anchor : Node ) => void } consequent _fn
* @ param { null | ( ( anchor : Node ) => void ) } [ alternate _fn ]
* @ param { ( branch : ( fn : ( anchor : Node ) => void , flag ? : boolean ) => void ) => void } fn
* @ param { boolean } [ elseif ] True if this is an ` {:else if ...} ` block rather than an ` {#if ...} ` , as that affects which transitions are considered 'local'
* @ returns { void }
* /
export function if _block ( node , get_condition , consequent _ fn, alternate _fn = null , elseif = false ) {
export function if _block ( node , fn, elseif = false ) {
if ( hydrating ) {
hydrate _next ( ) ;
}
@ -37,8 +35,18 @@ export function if_block(node, get_condition, consequent_fn, alternate_fn = null
var flags = elseif ? EFFECT _TRANSPARENT : 0 ;
block ( ( ) => {
if ( condition === ( condition = ! ! get _condition ( ) ) ) return ;
var has _branch = false ;
const set _branch = ( /** @type {(anchor: Node) => void} */ fn , flag = true ) => {
has _branch = true ;
update _branch ( flag , fn ) ;
} ;
const update _branch = (
/** @type {boolean | null} */ new _condition ,
/** @type {null | ((anchor: Node) => void)} */ fn
) => {
if ( condition === ( condition = new _condition ) ) return ;
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false ;
@ -60,8 +68,8 @@ export function if_block(node, get_condition, consequent_fn, alternate_fn = null
if ( condition ) {
if ( consequent _effect ) {
resume _effect ( consequent _effect ) ;
} else {
consequent _effect = branch ( ( ) => consequent_ fn( anchor ) ) ;
} else if ( fn ) {
consequent _effect = branch ( ( ) => fn( anchor ) ) ;
}
if ( alternate _effect ) {
@ -72,8 +80,8 @@ export function if_block(node, get_condition, consequent_fn, alternate_fn = null
} else {
if ( alternate _effect ) {
resume _effect ( alternate _effect ) ;
} else if ( alternate_ fn) {
alternate _effect = branch ( ( ) => alternate_ fn( anchor ) ) ;
} else if ( fn) {
alternate _effect = branch ( ( ) => fn( anchor ) ) ;
}
if ( consequent _effect ) {
@ -87,6 +95,14 @@ export function if_block(node, get_condition, consequent_fn, alternate_fn = null
// continue in hydration mode
set _hydrating ( true ) ;
}
} ;
block ( ( ) => {
has _branch = false ;
fn ( set _branch ) ;
if ( ! has _branch ) {
update _branch ( null , null ) ;
}
} , flags ) ;
if ( hydrating ) {