blockless
Rich Harris 10 months ago
parent c431330fcb
commit 94a7a322bb

@ -0,0 +1,23 @@
import { render_effect } from '../../reactivity/computations.js';
import { reconcile_html, remove } from '../../reconciler.js';
/**
* @param {Element | Text | Comment} anchor_node
* @param {() => string} get_value
* @param {boolean} svg
* @returns {void}
*/
export function html(anchor_node, get_value, svg) {
/** @type {string} */
let value;
/** @type {import('../../types.js').TemplateNode | import('../../types.js').TemplateNode[]} */
let dom;
render_effect(() => {
if (value === (value = get_value())) return;
if (dom) remove(dom);
dom = reconcile_html(anchor_node, value, svg);
});
}

@ -1571,32 +1571,6 @@ export function stringify(value) {
return typeof value === 'string' ? value : value == null ? '' : value + '';
}
/**
* @param {Element | Text | Comment} dom
* @param {() => string} get_value
* @param {boolean} svg
* @returns {void}
*/
export function html(dom, get_value, svg) {
/** @type {import('./types.js').TemplateNode | import('./types.js').TemplateNode[]} */
let html_dom;
/** @type {string} */
let value;
const effect = render_effect(() => {
if (value !== (value = get_value())) {
if (html_dom) {
remove(html_dom);
}
html_dom = reconcile_html(dom, value, svg);
}
});
push_destroy_fn(effect, () => {
if (html_dom) {
remove(html_dom);
}
});
}
/**
* @template P
* @param {HTMLElement} dom

@ -23,6 +23,7 @@ export {
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 { html } from './client/dom/blocks/html.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';

Loading…
Cancel
Save