Skip to content

Commit

Permalink
Allow templatizer to be used without owner or host prop forwarding. F…
Browse files Browse the repository at this point in the history
…ixes #4458
  • Loading branch information
kevinpschaaf committed Jan 10, 2018
1 parent 98b5aad commit bde5898
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/utils/templatize.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
children.push(n);
n.__templatizeInstance = this;
}
if (this.__templatizeOwner.__hideTemplateChildren__) {
if (this.__templatizeOwner &&
this.__templatizeOwner.__hideTemplateChildren__) {
this._showHideChildren(true);
}
// Flush props only when props are passed if instance props exist
Expand All @@ -96,15 +97,13 @@
*/
_configureProperties(props) {
let options = this.__templatizeOptions;
if (props) {
for (let iprop in options.instanceProps) {
if (iprop in props) {
this._setPendingProperty(iprop, props[iprop]);
}
if (options.forwardHostProp) {
for (let hprop in this.__hostProps) {
this._setPendingProperty(hprop, this.__dataHost['_host_' + hprop]);
}
}
for (let hprop in this.__hostProps) {
this._setPendingProperty(hprop, this.__dataHost['_host_' + hprop]);
for (let iprop in props) {
this._setPendingProperty(iprop, props[iprop]);
}
}
/**
Expand Down Expand Up @@ -464,7 +463,8 @@
throw new Error('A <template> can only be templatized once');
}
template.__templatizeOwner = owner;
let templateInfo = owner.constructor._parseTemplate(template);
const ctor = owner ? owner.constructor : TemplateInstanceBase;
let templateInfo = ctor._parseTemplate(template);
// Get memoized base class for the prototypical template, which
// includes property effects for binding template & forwarding
let baseClass = templateInfo.templatizeInstanceClass;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"polymer-build": "^2.1.1",
"run-sequence": "^2.2.0",
"through2": "^2.0.0",
"web-component-tester": "^6.4.1"
"web-component-tester": "^6.4.2"
},
"scripts": {
"build": "gulp",
Expand Down
29 changes: 29 additions & 0 deletions test/unit/templatize.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
</head>
<body>

<template id="standalone">
<div prop="[[prop]]">[[text]]</div>
</template>

<script>

suite('templatize basic', function() {
Expand Down Expand Up @@ -328,6 +332,31 @@

});

suite('templatize with no host', function() {

test('stamped with initial data', function() {
const template = document.getElementById('standalone').cloneNode(true);
const Template = Polymer.Templatize.templatize(template);
const inst = new Template({prop: 'prop', text: 'text'});
const div = inst.root.firstElementChild;
assert.equal(div.prop, 'prop');
assert.equal(div.textContent, 'text');
});

test('stamped with no initial data', function() {
const template = document.getElementById('standalone').cloneNode(true);
const Template = Polymer.Templatize.templatize(template);
const inst = new Template();
const div = inst.root.firstElementChild;
assert.equal(div.prop, undefined);
assert.equal(div.textContent.trim(), '');
inst.setProperties({prop: 'prop', text: 'text'});
assert.equal(div.prop, 'prop');
assert.equal(div.textContent, 'text');
});

});

</script>
</body>
</html>

0 comments on commit bde5898

Please sign in to comment.