move render code

blockless
Rich Harris 10 months ago
parent 9db48109df
commit 375575c4a5

@ -0,0 +1,27 @@
import { noop } from '../../../common.js';
import { destroy_effect, pause_effect, render_effect } from '../../reactivity/computations.js';
import { untrack } from '../../runtime.js';
/**
* @param {() => Function} get_snippet
* @param {Node} node
* @param {(() => any)[]} args
* @returns {void}
*/
export function snippet_effect(get_snippet, node, ...args) {
/** @type {import('../../types.js').EffectSignal | null} */
let effect;
render_effect(() => {
// Only rerender when the snippet function itself changes,
// not when an eagerly-read prop inside the snippet function changes
const snippet = get_snippet();
if (effect) {
pause_effect(effect, noop); // TODO we want to just destroy immediately
destroy_effect(effect);
}
effect = render_effect(() => untrack(() => snippet(node, ...args)), {}, true);
});
}

@ -2417,27 +2417,6 @@ export function sanitize_slots(props) {
return sanitized;
}
/**
* @param {() => Function} get_snippet
* @param {Node} node
* @param {(() => any)[]} args
* @returns {void}
*/
export function snippet_effect(get_snippet, node, ...args) {
const block = create_snippet_block();
render_effect(() => {
// Only rerender when the snippet function itself changes,
// not when an eagerly-read prop inside the snippet function changes
const snippet = get_snippet();
untrack(() => snippet(node, ...args));
return () => {
if (block.d !== null) {
remove(block.d);
}
};
}, block);
}
/**
* @param {Node} target
* @param {string} style_sheet_id

@ -24,6 +24,7 @@ export * from './client/dev/ownership.js';
export { await_block as await } from './client/dom/blocks/await.js';
export { if_block as if } from './client/dom/blocks/if.js';
export { key_block as key } from './client/dom/blocks/key.js';
export { snippet_effect } from './client/dom/blocks/render-tag.js';
export { component } from './client/dom/blocks/svelte-component.js';
export { element } from './client/dom/blocks/svelte-element.js';
export * from './client/dom/blocks/each.js';

Loading…
Cancel
Save