From bc7109928ba8984aa441f709217bfd7481dce5cc Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Mon, 22 Jun 2015 19:39:29 -0700 Subject: [PATCH 1/2] Coerce undefined to default when binding. Fixes #1742. --- src/standard/configure.html | 22 +++++++++++++++------- src/standard/effectBuilder.html | 4 ++++ test/unit/notify-path-elements.html | 17 ++++++++++------- test/unit/notify-path.html | 13 +++++++++++++ 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/standard/configure.html b/src/standard/configure.html index 467ce3be36..ddc9f8b00e 100644 --- a/src/standard/configure.html +++ b/src/standard/configure.html @@ -91,18 +91,26 @@ _configureProperties: function(properties, config) { for (var i in properties) { - var c = properties[i]; - if (c.value !== undefined) { - var value = c.value; - if (typeof value == 'function') { - // pass existing config values (this._config) to value function - value = value.call(this, this._config); - } + var value = this._defaultValueFromInfo(properties[i]); + if (value !== undefined) { config[i] = value; } } }, + _defaultValueFromInfo: function(info) { + var value = info && info.value; + if (typeof value == 'function') { + // pass existing config values (this._config) to value function + value = value.call(this, this._config); + } + return value; + }, + + _defaultValueForProp: function(prop) { + return this._defaultValueFromInfo(this.getPropertyInfo(prop)); + }, + _mixinConfigure: function(a, b) { for (var prop in b) { if (!this.getPropertyInfo(prop).readOnly) { diff --git a/src/standard/effectBuilder.html b/src/standard/effectBuilder.html index cf34c1feb2..65fa70da5e 100644 --- a/src/standard/effectBuilder.html +++ b/src/standard/effectBuilder.html @@ -263,6 +263,10 @@ (node.localName == 'input' && property == 'value')) { value = value == undefined ? '' : value; } + // coerce undefined back to default + if (value === undefined && node._defaultValueForProp) { + value = node._defaultValueForProp(property); + } // TODO(kschaaf): Ideally we'd use `fromAbove: true`, but this // breaks read-only properties // this._setProperty(property, value, true, node); diff --git a/test/unit/notify-path-elements.html b/test/unit/notify-path-elements.html index 2d386d01d5..76769a33a2 100644 --- a/test/unit/notify-path-elements.html +++ b/test/unit/notify-path-elements.html @@ -5,6 +5,10 @@ notifyingValue: { type: Number, notify: true + }, + valueWithDefault: { + type: Number, + value: 99 } } }); @@ -50,7 +54,7 @@ }, objValueChanged: function(value) { this.observerCounts.objValueChanged++; - assert.equal(this.obj.value, value); + assert.equal(this.obj && this.obj.value, value); }, }); @@ -95,7 +99,7 @@ }, objValueChanged: function(value) { this.observerCounts.objValueChanged++; - assert.equal(this.obj.value, value); + assert.equal(this.obj && this.obj.value, value); }, }); @@ -103,7 +107,7 @@