Skip to content

Commit

Permalink
Use _configValue to avoid setting readOnly. Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Jul 22, 2016
1 parent f2938ec commit 36467fa
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
// e.g. hand template content stored in notes to children as part of
// configure flow so templates have their content at ready time
this._configureAnnotationReferences();
// configure instance properties that may have been bound prior to upgrade
this._configureInstanceProperties();
// save copy of configuration that came from above
this._aboveConfig = this.mixin({}, this._config);
// save instance properties that may have been bound prior to upgrade
this._configureInstanceProperties(this._aboveConfig);
// get individual default values from property configs
var config = {};
// mixed-in behaviors
Expand Down Expand Up @@ -122,7 +122,7 @@
// to not b0rk accessors on the prototype.
// Perf testing has shown `hasOwnProperty` to be ok here.
if (!usePolyfillProto && this.hasOwnProperty(i)) {
config[i] = this[i];
this._configValue(i, this[i]);
delete this[i];
}
}
Expand Down
50 changes: 50 additions & 0 deletions test/unit/configure-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,53 @@
});
</script>
</dom-module>

<script>
window.XConfigLazy = {
is: 'x-config-lazy',
properties: {
noEffectProp: Number,
defaultUsesNoEffectProp: {
value: function() {
return this.noEffectProp * 2;
}
},
prop: {
observer: 'propChanged'
},
readOnlyProp: {
readOnly: true,
value: 'readOnly'
},
hadAttrProp: {
value: 'hadAttrProp',
observer: 'hadAttrPropChanged'
}
},
created: function() {
this.noEffectProp = 1;
this.propChanged = sinon.spy();
this.hadAttrPropChanged = sinon.spy();
}
};
</script>

<dom-module id="x-config-lazy-host">
<template>
<x-config-lazy id="lazy" prop="{{foo}}" read-only-prop="{{foo}}" had-attr-prop="attrValue"></x-config-lazy>
</template>
<script>
Polymer({
is: 'x-config-lazy-host',
properties: {
foo: {
value: 'foo',
observer: 'fooChanged'
}
},
fooChanged: function(foo) {
this.$.lazy.hadAttrProp = foo;
}
})
</script>
</dom-module>
19 changes: 19 additions & 0 deletions test/unit/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@
assert.equal(x.b, 2);
document.body.removeChild(x);
});

test('lazy upgrade binding use cases', function() {
// don't test if __proto__ is polyfilled (IE10); cannot be fixed in this case.
if (Polymer.Settings.usePolyfillProto) {
return;
}
var el = document.createElement('x-config-lazy-host');
document.body.appendChild(el);
Polymer(window.XConfigLazy);
assert.equal(el.$.lazy.noEffectProp, 1);
assert.equal(el.$.lazy.defaultUsesNoEffectProp, 2);
assert.equal(el.$.lazy.prop, 'foo');
assert.isTrue(el.$.lazy.propChanged.calledOnce);
assert.equal(el.$.lazy.readOnlyProp, 'readOnly');
assert.equal(el.$.lazy.hadAttrProp, 'foo');
assert.isTrue(el.$.lazy.hadAttrPropChanged.calledOnce);
document.body.removeChild(el);
});

});

</script>
Expand Down

0 comments on commit 36467fa

Please sign in to comment.