if.js — svelte Source File
Architecture documentation for if.js, a javascript file in the svelte codebase. 12 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 35d60eb3_a123_b735_48e0_4fce90c205ae["if.js"] f3948b0d_b92a_0767_ba6c_832767f4e2bb["hydration.js"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> f3948b0d_b92a_0767_ba6c_832767f4e2bb b31601aa_35ce_7827_5394_99fb97fa27d2["hydrate_next"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> b31601aa_35ce_7827_5394_99fb97fa27d2 965d3fe6_c7da_0708_eb2c_13a616bc4bca["read_hydration_instruction"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 965d3fe6_c7da_0708_eb2c_13a616bc4bca 8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e["skip_nodes"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e 40f27ad3_30bb_8f2a_3fb3_757088cf7428["set_hydrate_node"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 40f27ad3_30bb_8f2a_3fb3_757088cf7428 f5b61c69_d41c_bdb7_b931_5b8b3374332c["set_hydrating"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> f5b61c69_d41c_bdb7_b931_5b8b3374332c 1ae6fa4e_16ee_acdf_5e28_17eb0819fddb["effects.js"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 1ae6fa4e_16ee_acdf_5e28_17eb0819fddb 1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b["block"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b ee9aaeee_d18b_8f23_1c50_ace68f975516["branches.js"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> ee9aaeee_d18b_8f23_1c50_ace68f975516 60ab4ae8_779f_562b_010b_c2c26a4235d8["BranchManager"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 60ab4ae8_779f_562b_010b_c2c26a4235d8 73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e 54c2bfce_50b6_b8cc_4371_e1e14f283fb3["constants"] 35d60eb3_a123_b735_48e0_4fce90c205ae --> 54c2bfce_50b6_b8cc_4371_e1e14f283fb3 style 35d60eb3_a123_b735_48e0_4fce90c205ae fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { TemplateNode } from '#client' */
import { EFFECT_TRANSPARENT } from '#client/constants';
import {
hydrate_next,
hydrating,
read_hydration_instruction,
skip_nodes,
set_hydrate_node,
set_hydrating
} from '../hydration.js';
import { block } from '../../reactivity/effects.js';
import { BranchManager } from './branches.js';
import { HYDRATION_START, HYDRATION_START_ELSE } from '../../../../constants.js';
/**
* @param {TemplateNode} node
* @param {(branch: (fn: (anchor: Node) => void, key?: number | false) => 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, fn, elseif = false) {
if (hydrating) {
hydrate_next();
}
var branches = new BranchManager(node);
var flags = elseif ? EFFECT_TRANSPARENT : 0;
/**
* @param {number | false} key
* @param {null | ((anchor: Node) => void)} fn
*/
function update_branch(key, fn) {
if (hydrating) {
const data = read_hydration_instruction(node);
/**
* @type {number | false}
* "[" = branch 0, "[1" = branch 1, "[2" = branch 2, ..., "[!" = else (false)
*/
var hydrated_key;
if (data === HYDRATION_START) {
hydrated_key = 0;
} else if (data === HYDRATION_START_ELSE) {
hydrated_key = false;
} else {
hydrated_key = parseInt(data.substring(1)); // "[1", "[2", etc.
}
if (key !== hydrated_key) {
// Hydration mismatch: remove everything inside the anchor and start fresh.
// This could happen with `{#if browser}...{/if}`, for example
var anchor = skip_nodes();
set_hydrate_node(anchor);
branches.anchor = anchor;
set_hydrating(false);
branches.ensure(key, fn);
set_hydrating(true);
return;
}
}
branches.ensure(key, fn);
}
block(() => {
var has_branch = false;
fn((fn, key = 0) => {
has_branch = true;
update_branch(key, fn);
});
if (!has_branch) {
update_branch(false, null);
}
}, flags);
}
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does if.js do?
if.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Hydration subdomain.
What functions are defined in if.js?
if.js defines 1 function(s): if_block.
What does if.js depend on?
if.js imports 12 module(s): BranchManager, block, branches.js, constants, constants.js, effects.js, hydrate_next, hydration.js, and 4 more.
Where is if.js in the architecture?
if.js is located at packages/svelte/src/internal/client/dom/blocks/if.js (domain: ClientRuntime, subdomain: Hydration, directory: packages/svelte/src/internal/client/dom/blocks).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free