mirror of https://github.com/sveltejs/svelte
parent
76b156809b
commit
0119c1f04c
@ -1,45 +0,0 @@
|
|||||||
import {
|
|
||||||
ROOT_BLOCK,
|
|
||||||
HEAD_BLOCK,
|
|
||||||
DYNAMIC_ELEMENT_BLOCK,
|
|
||||||
DYNAMIC_COMPONENT_BLOCK,
|
|
||||||
SNIPPET_BLOCK
|
|
||||||
} from './constants.js';
|
|
||||||
import { current_block } from './runtime.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {boolean} intro
|
|
||||||
* @returns {import('./types.js').RootBlock}
|
|
||||||
*/
|
|
||||||
export function create_root_block(intro) {
|
|
||||||
return {
|
|
||||||
// dom
|
|
||||||
d: null,
|
|
||||||
// effect
|
|
||||||
e: null,
|
|
||||||
// intro
|
|
||||||
i: intro,
|
|
||||||
// parent
|
|
||||||
p: null,
|
|
||||||
// transition
|
|
||||||
r: null,
|
|
||||||
// type
|
|
||||||
t: ROOT_BLOCK
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @returns {import('./types.js').SnippetBlock} */
|
|
||||||
export function create_snippet_block() {
|
|
||||||
return {
|
|
||||||
// dom
|
|
||||||
d: null,
|
|
||||||
// parent
|
|
||||||
p: /** @type {import('./types.js').Block} */ (current_block),
|
|
||||||
// effect
|
|
||||||
e: null,
|
|
||||||
// transition
|
|
||||||
r: null,
|
|
||||||
// type
|
|
||||||
t: SNIPPET_BLOCK
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
import { SNIPPET_BLOCK } from '../../constants.js';
|
||||||
|
import { render_effect } from '../../reactivity/effects.js';
|
||||||
|
import { remove } from '../../reconciler.js';
|
||||||
|
import { current_block, untrack } from '../../runtime.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {() => Function | null | undefined} get_snippet
|
||||||
|
* @param {Node} node
|
||||||
|
* @param {(() => any)[]} args
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
export function snippet(get_snippet, node, ...args) {
|
||||||
|
/** @type {import('#client').SnippetBlock} */
|
||||||
|
const block = {
|
||||||
|
// dom
|
||||||
|
d: null,
|
||||||
|
// parent
|
||||||
|
p: /** @type {import('#client').Block} */ (current_block),
|
||||||
|
// effect
|
||||||
|
e: null,
|
||||||
|
// transition
|
||||||
|
r: null,
|
||||||
|
// type
|
||||||
|
t: 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();
|
||||||
|
if (snippet) {
|
||||||
|
untrack(() => snippet(node, ...args));
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (block.d !== null) {
|
||||||
|
remove(block.d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, block);
|
||||||
|
}
|
||||||
Loading…
Reference in new issue