|
|
|
@ -31,8 +31,8 @@ function create_if_block() {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {Comment} anchor
|
|
|
|
* @param {Comment} anchor
|
|
|
|
* @param {() => boolean} get_condition
|
|
|
|
* @param {() => boolean} get_condition
|
|
|
|
* @param {(anchor: Node) => void} consequent_fn
|
|
|
|
* @param {(anchor: Node) => import('#client').TemplateNode | import('#client').TemplateNode[]} consequent_fn
|
|
|
|
* @param {null | ((anchor: Node) => void)} alternate_fn
|
|
|
|
* @param {null | ((anchor: Node) => import('#client').TemplateNode | import('#client').TemplateNode[])} alternate_fn
|
|
|
|
* @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local'
|
|
|
|
* @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}
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -41,11 +41,11 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
|
|
|
|
|
|
|
|
|
|
|
|
hydrate_block_anchor(anchor);
|
|
|
|
hydrate_block_anchor(anchor);
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
|
|
|
|
/** @type {undefined | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
|
|
|
|
let consequent_dom = null;
|
|
|
|
let consequent_dom;
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
|
|
|
|
/** @type {undefined | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
|
|
|
|
let alternate_dom = null;
|
|
|
|
let alternate_dom;
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('#client').Effect | null} */
|
|
|
|
/** @type {import('#client').Effect | null} */
|
|
|
|
let consequent_effect = null;
|
|
|
|
let consequent_effect = null;
|
|
|
|
@ -87,8 +87,7 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
consequent_effect = render_effect(
|
|
|
|
consequent_effect = render_effect(
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
consequent_fn(anchor);
|
|
|
|
consequent_dom = consequent_fn(anchor);
|
|
|
|
consequent_dom = block.d;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mismatch) {
|
|
|
|
if (mismatch) {
|
|
|
|
// Set fragment so that Svelte continues to operate in hydration mode
|
|
|
|
// Set fragment so that Svelte continues to operate in hydration mode
|
|
|
|
@ -98,9 +97,9 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
|
|
|
|
return () => {
|
|
|
|
return () => {
|
|
|
|
// TODO make this unnecessary by linking the dom to the effect,
|
|
|
|
// TODO make this unnecessary by linking the dom to the effect,
|
|
|
|
// and removing automatically on teardown
|
|
|
|
// and removing automatically on teardown
|
|
|
|
if (consequent_dom !== null) {
|
|
|
|
if (consequent_dom !== undefined) {
|
|
|
|
remove(consequent_dom);
|
|
|
|
remove(consequent_dom);
|
|
|
|
consequent_dom = null;
|
|
|
|
consequent_dom = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
@ -121,8 +120,7 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
|
|
|
|
} else if (alternate_fn) {
|
|
|
|
} else if (alternate_fn) {
|
|
|
|
alternate_effect = render_effect(
|
|
|
|
alternate_effect = render_effect(
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
alternate_fn(anchor);
|
|
|
|
alternate_dom = alternate_fn(anchor);
|
|
|
|
alternate_dom = block.d;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mismatch) {
|
|
|
|
if (mismatch) {
|
|
|
|
// Set fragment so that Svelte continues to operate in hydration mode
|
|
|
|
// Set fragment so that Svelte continues to operate in hydration mode
|
|
|
|
@ -132,9 +130,9 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
|
|
|
|
return () => {
|
|
|
|
return () => {
|
|
|
|
// TODO make this unnecessary by linking the dom to the effect,
|
|
|
|
// TODO make this unnecessary by linking the dom to the effect,
|
|
|
|
// and removing automatically on teardown
|
|
|
|
// and removing automatically on teardown
|
|
|
|
if (alternate_dom !== null) {
|
|
|
|
if (alternate_dom !== undefined) {
|
|
|
|
remove(alternate_dom);
|
|
|
|
remove(alternate_dom);
|
|
|
|
alternate_dom = null;
|
|
|
|
alternate_dom = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
@ -159,17 +157,18 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
|
|
|
|
if_effect.ondestroy = () => {
|
|
|
|
if_effect.ondestroy = () => {
|
|
|
|
// TODO make this unnecessary by linking the dom to the effect,
|
|
|
|
// TODO make this unnecessary by linking the dom to the effect,
|
|
|
|
// and removing automatically on teardown
|
|
|
|
// and removing automatically on teardown
|
|
|
|
if (consequent_dom !== null) {
|
|
|
|
if (consequent_dom !== undefined) {
|
|
|
|
remove(consequent_dom);
|
|
|
|
remove(consequent_dom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (alternate_dom !== null) {
|
|
|
|
if (alternate_dom !== undefined) {
|
|
|
|
remove(alternate_dom);
|
|
|
|
remove(alternate_dom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (consequent_effect) {
|
|
|
|
if (consequent_effect) {
|
|
|
|
destroy_effect(consequent_effect);
|
|
|
|
destroy_effect(consequent_effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (alternate_effect) {
|
|
|
|
if (alternate_effect) {
|
|
|
|
destroy_effect(alternate_effect);
|
|
|
|
destroy_effect(alternate_effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|