From 5748e6a760881ac4cb1374392959c7ab13d8bd3c Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 11 Aug 2023 17:42:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/html.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/html.js b/src/html.js index 533db1a..1842aa3 100644 --- a/src/html.js +++ b/src/html.js @@ -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 {