Skip to content

Commit

Permalink
Merge branch 'fix-for-2348' of https://github.com/nazar-pc/polymer in…
Browse files Browse the repository at this point in the history
…to nazar-pc-fix-for-2348

# Conflicts:
#	test/unit/configure.html

+ use hasOwnProperty check; benchmarking indicates perf is ok.
+ refine test.
  • Loading branch information
Steven Orvell committed Feb 13, 2016
2 parents de039f8 + ecd9b09 commit d99e693
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@
_configureProperties: function(properties, config) {
for (var i in properties) {
var c = properties[i];
// don't accept undefined values
if (c.value !== undefined) {
// Allow properties set before upgrade on the instance
// to override default values. This allows late upgrade + an early set
// to not b0rk accessors on the prototype.
// Perf testing has shown `hasOwnProperty` to be ok here.
if (this.hasOwnProperty(i)) {
config[i] = this[i];
delete this[i];
} else if (c.value !== undefined) {
var value = c.value;
if (typeof value == 'function') {
// pass existing config values (this._config) to value function
Expand Down
26 changes: 26 additions & 0 deletions test/unit/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,32 @@
assert.equal(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
});

test('pre-register property assignment does not break getters and setters', function() {
var x = document.createElement('x-late-register');
document.body.appendChild(x);
// set property
x.shouldChange = '1';
// now register element
Polymer({
is: 'x-late-register',
properties: {
shouldChange : {
observer: 'shouldChangeCallback',
type: String
}
},
shouldChangeCallback: function() {
this.textContent = this.shouldChange;
}
});
CustomElements.takeRecords();
assert.equal(x.shouldChange, '1');
assert.equal(x.shouldChange, x.textContent);
x.shouldChange = '2';
assert.equal(x.shouldChange, '2');
assert.equal(x.shouldChange, x.textContent);
document.body.removeChild(x);
});
});

</script>
Expand Down

0 comments on commit d99e693

Please sign in to comment.