use function composition

pull/15538/head
Rich Harris 4 months ago
parent 408955dae6
commit 7d1551b3dd

@ -12,17 +12,12 @@ import * as b from '../../../../utils/builders.js';
* @returns
*/
function get_template_function(namespace, state) {
const contains_script_tag = state.template.contains_script_tag;
return (
namespace === 'svg'
? contains_script_tag
? '$.svg_template_with_script'
: '$.ns_template'
? '$.ns_template'
: namespace === 'mathml'
? '$.mathml_template'
: contains_script_tag
? '$.template_with_script'
: '$.template'
: '$.template'
).concat(state.options.templatingMode === 'functional' ? '_fn' : '');
}
@ -67,6 +62,10 @@ export function transform_template(state, namespace, flags) {
flags ? b.literal(flags) : undefined
);
if (state.template.contains_script_tag) {
call = b.call(`$.with_script`, call);
}
if (dev) {
return b.call(
'$.add_locations',

@ -165,24 +165,10 @@ export function template_fn(structure, flags) {
}
/**
* @param {string} content
* @param {number} flags
* @returns {() => Node | Node[]}
* @param {() => Element | DocumentFragment} fn
*/
/*#__NO_SIDE_EFFECTS__*/
export function template_with_script(content, flags) {
var fn = template(content, flags);
return () => run_scripts(/** @type {Element | DocumentFragment} */ (fn()));
}
/**
* @param {Array<TemplateStructure>} structure
* @param {number} flags
* @returns {() => Node | Node[]}
*/ /*#__NO_SIDE_EFFECTS__*/
export function template_with_script_fn(structure, flags) {
var templated_fn = template_fn(structure, flags);
return () => run_scripts(/** @type {Element | DocumentFragment} */ (templated_fn()));
export function with_script(fn) {
return () => run_scripts(fn());
}
/**
@ -290,28 +276,6 @@ export function ns_template_fn(structure, flags, ns = 'svg') {
};
}
/**
* @param {string} content
* @param {number} flags
* @returns {() => Node | Node[]}
*/
/*#__NO_SIDE_EFFECTS__*/
export function svg_template_with_script(content, flags) {
var fn = ns_template(content, flags);
return () => run_scripts(/** @type {Element | DocumentFragment} */ (fn()));
}
/**
* @param {Array<TemplateStructure>} structure
* @param {number} flags
* @returns {() => Node | Node[]}
*/
/*#__NO_SIDE_EFFECTS__*/
export function svg_template_with_script_fn(structure, flags) {
var templated_fn = ns_template_fn(structure, flags);
return () => run_scripts(/** @type {Element | DocumentFragment} */ (templated_fn()));
}
/**
* @param {string} content
* @param {number} flags

@ -90,16 +90,13 @@ export {
comment,
ns_template,
ns_template_fn,
svg_template_with_script,
svg_template_with_script_fn,
mathml_template,
mathml_template_fn,
template,
template_fn,
template_with_script,
template_with_script_fn,
text,
props_id
props_id,
with_script
} from './dom/template.js';
export { user_derived as derived, derived_safe_equal } from './reactivity/deriveds.js';
export {

Loading…
Cancel
Save