修改模板缓存逻辑

dev
yutent 2023-08-11 17:42:27 +08:00
parent 289c7142ef
commit 5748e6a760
1 changed files with 11 additions and 8 deletions

View File

@ -48,7 +48,7 @@ const EVENT_PART = 5
const ELEMENT_PART = 6
const COMMENT_PART = 7
const templateCache = new WeakMap()
const TEMPLATE_CACHE = new Map()
const walker = document.createTreeWalker(document, 129, null, false)
function noop() {}
@ -436,10 +436,11 @@ class ChildPart {
}
}
#getTemplate(result) {
let template = templateCache.get(result.strings)
let template = TEMPLATE_CACHE.get(result.strings.join())
if (template === void 0) {
template = new Template(result, this.options)
templateCache.set(result.strings, template)
TEMPLATE_CACHE.set(result.strings.join(), template)
}
return template
}
@ -701,12 +702,13 @@ export function render(value, container, options = {}) {
let part = container[WC_PART]
if (part === void 0) {
container[WC_PART] = part = new ChildPart(
part = new ChildPart(
container.insertBefore(createMarker(), null),
null,
void 0,
options
)
container[WC_PART] = part
}
part._$setValue(value)
@ -720,10 +722,11 @@ export function html(strings, ...values) {
values
}
}
export function raw(str, ...args) {
let strings = args.length ? str.split('%s') : [str]
strings.raw = strings
return html(strings, ...args)
export function raw(str, values = []) {
let strings = values.length ? str.split('%s') : [str]
strings.raw = true
return html(strings, ...values)
}
export function svg(strings, ...values) {
return {