MCPcopy
hub / github.com/sveltejs/svelte / attach

Function attach

packages/svelte/src/internal/client/dom/elements/attachments.js:12–33  ·  view source on GitHub ↗
(node, get_fn)

Source from the content-addressed store, hash-verified

10 * @param {() => (node: Element) => void} get_fn
11 */
12export function attach(node, get_fn) {
13 /** @type {false | undefined | ((node: Element) => void)} */
14 var fn = undefined;
15
16 /** @type {Effect | null} */
17 var e;
18
19 managed(() => {
20 if (fn !== (fn = get_fn())) {
21 if (e) {
22 destroy_effect(e);
23 e = null;
24 }
25
26 if (fn) {
27 e = branch(() => {
28 effect(() => /** @type {(node: Element) => void} */ (fn)(node));
29 });
30 }
31 }
32 });
33}

Callers 2

attribute_effectFunction · 0.90
selectedcontentFunction · 0.90

Calls 4

managedFunction · 0.90
destroy_effectFunction · 0.90
branchFunction · 0.90
effectFunction · 0.90

Tested by

no test coverage detected