All files / src/internal/client/dom/blocks snippet.js

100% Statements 22/22
100% Branches 5/5
100% Functions 1/1
100% Lines 21/21

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 222x 2x 2x 2x 2x 2x 2x 2x 2x 2x 52x 52x 52x 52x 70x 66x 66x 66x 66x 52x 52x  
import { branch, render_effect } from '../../reactivity/effects.js';
 
/**
 * @template {(node: import('#client').TemplateNode, ...args: any[]) => import('#client').Dom} SnippetFn
 * @param {() => SnippetFn | null | undefined} get_snippet
 * @param {import('#client').TemplateNode} node
 * @param {(() => any)[]} args
 * @returns {void}
 */
export function snippet(get_snippet, node, ...args) {
	/** @type {SnippetFn | null | undefined} */
	var snippet;
 
	render_effect(() => {
		if (snippet === (snippet = get_snippet())) return;
 
		if (snippet) {
			branch(() => /** @type {SnippetFn} */ (snippet)(node, ...args));
		}
	});
}