diff --git a/src/standard/configure.html b/src/standard/configure.html index 2fc292b4..0619bad2 100644 --- a/src/standard/configure.html +++ b/src/standard/configure.html @@ -114,8 +114,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN _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 diff --git a/test/unit/configure.html b/test/unit/configure.html index 996dc62c..a51a1d75 100644 --- a/test/unit/configure.html +++ b/test/unit/configure.html @@ -103,6 +103,32 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN 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); + }); });