Skip to content

Commit f0cbc83

Browse files
committed
Updates from review.
1 parent ff25283 commit f0cbc83

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

lib/mixins/property-effects.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,17 +2691,24 @@ export const PropertyEffects = dedupingMixin(superClass => {
26912691
}
26922692
if (instanceBinding) {
26932693
// For instance-time binding, create instance of template metadata
2694-
// and link into list of templates if necessary
2694+
// and link into tree of templates if necessary
26952695
templateInfo = /** @type {!TemplateInfo} */(Object.create(templateInfo));
26962696
templateInfo.wasPreBound = wasPreBound;
26972697
if (!this.__templateInfo) {
26982698
// Set the info to the root of the tree
26992699
this.__templateInfo = templateInfo;
27002700
} else {
27012701
// Append this template info onto the end of its parent template's
2702-
// nested template list; if this template was not nested in another
2702+
// list, which will determine the tree structure via which property
2703+
// effects are run; if this template was not nested in another
27032704
// template, use the root template (the first stamped one) as the
2704-
// parent
2705+
// parent. Note, `parent` is the `templateInfo` instance for this
2706+
// template's containing template, which was set up in
2707+
// `applyTemplateContent`. While a given template's `parent` is
2708+
// given, it is only added to the parent list at the point that it is
2709+
// being bound, since a template may or may not ever be stamped, and
2710+
// may be stamped more than once (in which case it will be in the
2711+
// tree more than once).
27052712
const parent = templateInfo.parent || this.__templateInfo;
27062713
const previous = parent.lastChild;
27072714
parent.lastChild = templateInfo;
@@ -2800,7 +2807,10 @@ export const PropertyEffects = dedupingMixin(superClass => {
28002807
* @protected
28012808
*/
28022809
_removeBoundDom(dom) {
2803-
// Unlink template info
2810+
// Unlink template info; Note that while the child is unlinked from its
2811+
// parent list, a template's `parent` reference is never removed, since
2812+
// this is is determined by the tree structure and applied at
2813+
// `applyTemplateContent` time.
28042814
let templateInfo = dom.templateInfo;
28052815
const {previousSibling, nextSibling, parent} = templateInfo;
28062816
if (previousSibling) {
@@ -2955,19 +2965,31 @@ export const PropertyEffects = dedupingMixin(superClass => {
29552965
if (removeNestedTemplates && (isDomIf || isDomRepeat)) {
29562966
parent.removeChild(node);
29572967
nodeInfo.parentInfo.templateInfo = nestedTemplateInfo;
2968+
// Ensure the parent dom-if/repeat is noted since it now has bindings;
2969+
// it may not have been if it did not have its own bindings
29582970
nodeInfo = nodeInfo.parentInfo;
29592971
nodeInfo.noted = true;
29602972
noted = false;
29612973
}
29622974
// Merge host props into outer template and add bindings
29632975
let hostProps = nestedTemplateInfo.hostProps;
29642976
if (fastDomIf && isDomIf) {
2977+
// `fastDomIf` mode uses runtime-template stamping to add accessors/
2978+
// effects to properties used in its template; as such we don't need to
2979+
// tax the host element with `_host_` bindings for the `dom-if`.
2980+
// However, in the event it is nested in a `dom-repeat`, it is still
2981+
// important that its host properties are added to the
2982+
// TemplateInstance's `hostProps` so that they are forwarded to the
2983+
// TemplateInstance.
29652984
if (hostProps) {
2985+
templateInfo.hostProps =
2986+
Object.assign(templateInfo.hostProps || {}, hostProps);
2987+
// Ensure the dom-if is noted so that it has a __dataHost, since
2988+
// `fastDomIf` uses the host for runtime template stamping; note this
2989+
// was already ensured above in the `removeNestedTemplates` case
29662990
if (!removeNestedTemplates) {
29672991
nodeInfo.parentInfo.noted = true;
29682992
}
2969-
templateInfo.hostProps =
2970-
Object.assign(templateInfo.hostProps || {}, hostProps);
29712993
}
29722994
} else {
29732995
let mode = '{';

lib/mixins/template-stamp.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ export const TemplateStamp = dedupingMixin(
257257
if (element.hasAttributes && element.hasAttributes()) {
258258
noted = this._parseTemplateNodeAttributes(element, templateInfo, nodeInfo) || noted;
259259
}
260+
// Checking `nodeInfo.noted` allows a child node of this node (who gets
261+
// access to `parentInfo`) to cause the parent to be noted, which
262+
// otherwise has no return path via `_parseTemplateChildNodes` (used by
263+
// some optimizations)
260264
return noted || nodeInfo.noted;
261265
}
262266

@@ -448,6 +452,9 @@ export const TemplateStamp = dedupingMixin(
448452
window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
449453
HTMLTemplateElement.decorate(template);
450454
}
455+
// Accepting the `templateInfo` via an argument allows for creating
456+
// instances of the `templateInfo` by the caller, useful for adding
457+
// instance-time information to the prototypical data
451458
templateInfo = templateInfo || this.constructor._parseTemplate(template);
452459
let nodeInfo = templateInfo.nodeInfoList;
453460
let content = templateInfo.content || template.content;

lib/utils/settings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,12 @@ export let removeNestedTemplates =
289289
* Sets `removeNestedTemplates` globally, to eliminate nested templates
290290
* inside `dom-if` and `dom-repeat` as part of template parsing.
291291
*
292-
* @param {boolean} useCemoveNestedTemplates enable or disable removing nested
292+
* @param {boolean} useRemoveNestedTemplates enable or disable removing nested
293293
* templates during parsing
294294
* @return {void}
295295
*/
296-
export const setRemoveNestedTemplates = function(useCemoveNestedTemplates) {
297-
removeNestedTemplates = useCemoveNestedTemplates;
296+
export const setRemoveNestedTemplates = function(useRemoveNestedTemplates) {
297+
removeNestedTemplates = useRemoveNestedTemplates;
298298
};
299299

300300
/**

lib/utils/templatize.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ function addPropagateEffects(target, templateInfo, options, methodHost) {
405405
// Create a cached subclass of the base custom element class onto which
406406
// to put the template-specific propagate effects
407407
/** @private */
408-
klass = class TemplatizedTemplateExtension extends templatizedBase {};
408+
klass = templateInfo.templatizeTemplateClass =
409+
class TemplatizedTemplateExtension extends templatizedBase {};
409410
}
410411
// Add template - >instances effects
411412
// and host <- template effects

0 commit comments

Comments
 (0)