Skip to content

Commit

Permalink
Fix _hasAccessor for readOnly. Collapse addBinding & addBindingEffects
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Apr 7, 2017
1 parent ea4e7d9 commit 396c102
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
4 changes: 3 additions & 1 deletion lib/mixins/element-mixin.html
Expand Up @@ -576,7 +576,9 @@
let value = typeof info.value == 'function' ?
info.value.call(this) :
info.value;
if (this._hasPropertyEffect(p)) {
// Set via `_setProperty` if there is an accessor, to enable
// initializing readOnly property defaults
if (this._hasAccessor(p)) {
this._setProperty(p, value)
} else {
this[p] = value;
Expand Down
29 changes: 11 additions & 18 deletions lib/mixins/property-effects.html
Expand Up @@ -447,16 +447,6 @@

// -- bindings ----------------------------------------------

function addBinding(nodeInfo, kind, target, parts, literal) {
nodeInfo.bindings = nodeInfo.bindings || [];
let binding = {
kind, target, parts, literal,
isCompound: (parts.length !== 1)
};
nodeInfo.bindings.push(binding);
return binding;
}

/**
* Adds "binding" property effects for the template annotation
* ("note" for short) and node index specified. These may either be normal
Expand All @@ -471,10 +461,17 @@
* be included as a dependency to the effect.
* @private
*/
function addBindingEffects(constructor, templateInfo, binding, index) {
function addBinding(constructor, templateInfo, nodeInfo, kind, target, parts, literal) {
// Create binding metadata and add to nodeInfo
nodeInfo.bindings = nodeInfo.bindings || [];
let binding = { kind, target, parts, literal, isCompound: (parts.length !== 1) };
let index = templateInfo.nodeInfoList.length;
nodeInfo.bindings.push(binding);
// Add 2-way binding listener metadata to templateInfo
if (shouldAddListener(binding)) {
addAnnotatedListener(templateInfo, index, binding);
}
// Add "propagate" property effects to templateInfo
for (let i=0; i<binding.parts.length; i++) {
let part = binding.parts[i];
if (!part.literal) {
Expand Down Expand Up @@ -2103,9 +2100,7 @@
// NOTE: default to a space here so the textNode remains; some browsers
// (IE) evacipate an empty textNode following cloneNode/importNode.
node.textContent = literalFromParts(parts) || ' ';
let binding = addBinding(nodeInfo, 'text', 'textContent', parts);
let idx = templateInfo.nodeInfoList.length;
addBindingEffects(this, templateInfo, binding, idx);
addBinding(this, templateInfo, nodeInfo, 'text', 'textContent', parts);
noted = true;
}
}
Expand Down Expand Up @@ -2159,8 +2154,7 @@
if (kind === 'property') {
name = Polymer.CaseMap.dashToCamelCase(name);
}
let binding = addBinding(nodeInfo, kind, name, parts, literal);
addBindingEffects(this, templateInfo, binding, templateInfo.nodeInfoList.length);
addBinding(this, templateInfo, nodeInfo, kind, name, parts, literal);
return true;
} else {
return super._parseTemplateNodeAttribute(node, templateInfo, nodeInfo, name, value);
Expand All @@ -2187,8 +2181,7 @@
let mode = '{';
for (let source in hostProps) {
let parts = [{ mode, source, dependencies: [source] }];
let binding = addBinding(nodeInfo, 'property', '_host_' + source, parts);
addBindingEffects(this, templateInfo, binding, templateInfo.nodeInfoList.length);
addBinding(this, templateInfo, nodeInfo, 'property', '_host_' + source, parts);
}
return noted;
}
Expand Down

0 comments on commit 396c102

Please sign in to comment.