From 65a5b48c38be5866a9e9d2e450218ed7f739aadc Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Wed, 10 Apr 2019 14:47:39 -0700 Subject: [PATCH 1/3] Avoid upgrading template if no hostProps, for better perf. --- lib/utils/templatize.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utils/templatize.js b/lib/utils/templatize.js index 9f05135470..7cdcb8ca4a 100644 --- a/lib/utils/templatize.js +++ b/lib/utils/templatize.js @@ -364,7 +364,11 @@ function createTemplatizerClass(template, templateInfo, options) { */ function addPropagateEffects(template, templateInfo, options) { let userForwardHostProp = options.forwardHostProp; - if (userForwardHostProp) { + const hasHostProps = templateInfo.hasHostProps || + (templateInfo.hasHostProps = + Boolean(templateInfo.hostProps && + Object.keys(templateInfo.hostProps).length)); + if (userForwardHostProp && hasHostProps) { // Provide data API and property effects on memoized template class let klass = templateInfo.templatizeTemplateClass; if (!klass) { From f1a9d4fa8694e246d7d1cf11b87e11de1a231ac3 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Wed, 10 Apr 2019 14:55:40 -0700 Subject: [PATCH 2/3] Simplify --- lib/utils/templatize.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/utils/templatize.js b/lib/utils/templatize.js index 7cdcb8ca4a..859c8a2f8c 100644 --- a/lib/utils/templatize.js +++ b/lib/utils/templatize.js @@ -364,11 +364,7 @@ function createTemplatizerClass(template, templateInfo, options) { */ function addPropagateEffects(template, templateInfo, options) { let userForwardHostProp = options.forwardHostProp; - const hasHostProps = templateInfo.hasHostProps || - (templateInfo.hasHostProps = - Boolean(templateInfo.hostProps && - Object.keys(templateInfo.hostProps).length)); - if (userForwardHostProp && hasHostProps) { + if (userForwardHostProp && templateInfo.hasHostProps) { // Provide data API and property effects on memoized template class let klass = templateInfo.templatizeTemplateClass; if (!klass) { @@ -427,6 +423,9 @@ function addNotifyEffects(klass, template, templateInfo, options) { } if (options.forwardHostProp && template.__dataHost) { for (let hprop in hostProps) { + if (!templateInfo.hasHostProps) { + templateInfo.hasHostProps = true; + } klass.prototype._addPropertyEffect(hprop, klass.prototype.PROPERTY_EFFECT_TYPES.NOTIFY, {fn: createNotifyHostPropEffect()}); From c7eb7c1984e2a85793ccb0c00020cf062066160c Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Fri, 12 Apr 2019 18:17:44 -0700 Subject: [PATCH 3/3] [ci skip] Add comment --- lib/utils/templatize.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/utils/templatize.js b/lib/utils/templatize.js index 859c8a2f8c..7d4ed9dd3f 100644 --- a/lib/utils/templatize.js +++ b/lib/utils/templatize.js @@ -360,6 +360,9 @@ function createTemplatizerClass(template, templateInfo, options) { } /** + * Adds propagate effects from the template to the template instance for + * properties that the host binds to the template using the `_host_` prefix. + * * @suppress {missingProperties} class.prototype is not defined for some reason */ function addPropagateEffects(template, templateInfo, options) { @@ -423,6 +426,8 @@ function addNotifyEffects(klass, template, templateInfo, options) { } if (options.forwardHostProp && template.__dataHost) { for (let hprop in hostProps) { + // As we're iterating hostProps in this function, note whether + // there were any, for an optimization in addPropagateEffects if (!templateInfo.hasHostProps) { templateInfo.hasHostProps = true; }