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

Function fromAction

packages/svelte/src/attachments/index.js:96–113  ·  view source on GitHub ↗
(action, fn = /** @type {() => T} */ (noop))

Source from the content-addressed store, hash-verified

94 * @since 5.32
95 */
96export function fromAction(action, fn = /** @type {() => T} */ (noop)) {
97 return (element) => {
98 const { update, destroy } = untrack(() => action(element, fn()) ?? {});
99
100 if (update) {
101 var ran = false;
102 render_effect(() => {
103 const arg = fn();
104 if (ran) update(arg);
105 });
106 ran = true;
107 }
108
109 if (destroy) {
110 teardown(destroy);
111 }
112 };
113}

Callers

nothing calls this directly

Calls 6

untrackFunction · 0.90
render_effectFunction · 0.90
teardownFunction · 0.90
actionFunction · 0.85
fnFunction · 0.50
updateFunction · 0.50

Tested by

no test coverage detected