All files / src/internal/client/dom/blocks svelte-component.js

100% Statements 44/44
100% Branches 11/11
100% Functions 1/1
100% Lines 42/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 432x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 92x 41x 41x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 147x 142x 147x 51x 51x 51x 93x 137x 85x 85x 92x 92x 92x 41x 41x 92x  
/** @import { TemplateNode, Dom, Effect } from '#client' */
import { block, branch, pause_effect } from '../../reactivity/effects.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
 
/**
 * @template P
 * @template {(props: P) => void} C
 * @param {TemplateNode} node
 * @param {() => C} get_component
 * @param {(anchor: TemplateNode, component: C) => Dom | void} render_fn
 * @returns {void}
 */
export function component(node, get_component, render_fn) {
	if (hydrating) {
		hydrate_next();
	}
 
	var anchor = node;
 
	/** @type {C} */
	var component;
 
	/** @type {Effect | null} */
	var effect;
 
	block(() => {
		if (component === (component = get_component())) return;
 
		if (effect) {
			pause_effect(effect);
			effect = null;
		}
 
		if (component) {
			effect = branch(() => render_fn(anchor, component));
		}
	});
 
	if (hydrating) {
		anchor = hydrate_node;
	}
}