@@ -200,20 +200,28 @@ Component.prototype = {
200200 * @param {string } attrValue - HTML attribute value.
201201 * If undefined, use the cached attribute value and continue updating properties.
202202 */
203- updateProperties : function ( attrValue ) {
203+ updateProperties : function ( attrValue , clobber ) {
204204 var el = this . el ;
205205 var isSinglePropSchema = isSingleProp ( this . schema ) ;
206206 var oldData = extendProperties ( { } , this . data , isSinglePropSchema ) ;
207+ var skipTypeChecking = typeof this . previousAttrValue === 'object' && attrValue === this . previousAttrValue ;
208+ var currentAttrValue = ! clobber && this . attrValue ;
209+ this . previousAttrValue = attrValue ;
207210
208- if ( attrValue !== undefined ) { this . updateCachedAttrValue ( attrValue ) ; }
211+ if ( ! el . hasLoaded ) {
212+ if ( attrValue !== undefined ) { this . updateCachedAttrValue ( attrValue ) ; }
213+ return ;
214+ }
209215
210- if ( ! el . hasLoaded ) { return ; }
216+ attrValue = this . parseAttrValueForCache ( attrValue ) ;
211217
212218 if ( this . updateSchema ) {
213- this . updateSchema ( buildData ( el , this . name , this . attrName , this . schema , this . attrValue ,
219+ this . updateSchema ( buildData ( el , this . name , this . attrName , this . schema , attrValue , currentAttrValue ,
214220 true ) ) ;
215221 }
216- this . data = buildData ( el , this . name , this . attrName , this . schema , this . attrValue ) ;
222+ this . data = buildData ( el , this . name , this . attrName , this . schema , attrValue , currentAttrValue , false , skipTypeChecking ) ;
223+
224+ if ( attrValue !== undefined ) { this . updateCachedAttrValue ( attrValue ) ; }
217225
218226 if ( ! this . initialized ) {
219227 // Component is being already initialized
@@ -236,7 +244,7 @@ Component.prototype = {
236244 } , false ) ;
237245 } else {
238246 // Don't update if properties haven't changed
239- if ( utils . deepEqual ( oldData , this . data ) ) { return ; }
247+ if ( ! skipTypeChecking && utils . deepEqual ( oldData , this . data ) ) { return ; }
240248
241249 // Update component.
242250 this . update ( oldData ) ;
@@ -390,7 +398,7 @@ module.exports.registerComponent = function (name, definition) {
390398 * @param {boolean } silent - Suppress warning messages.
391399 * @return {object } The component data
392400 */
393- function buildData ( el , name , attrName , schema , elData , silent ) {
401+ function buildData ( el , name , attrName , schema , elData , oldElData , silent , skipTypeChecking ) {
394402 var componentDefined = elData !== undefined && elData !== null ;
395403 var data ;
396404 var isSinglePropSchema = isSingleProp ( schema ) ;
@@ -400,9 +408,10 @@ function buildData (el, name, attrName, schema, elData, silent) {
400408 if ( isSinglePropSchema ) {
401409 data = schema . default ;
402410 } else {
403- data = { } ;
411+ data = typeof oldElData === 'object' ? utils . extend ( { } , oldElData ) : { } ;
404412 Object . keys ( schema ) . forEach ( function applyDefault ( key ) {
405413 var defaultValue = schema [ key ] . default ;
414+ if ( data [ key ] ) { return ; }
406415 data [ key ] = defaultValue && defaultValue . constructor === Object
407416 ? utils . extend ( { } , defaultValue )
408417 : defaultValue ;
@@ -420,14 +429,19 @@ function buildData (el, name, attrName, schema, elData, silent) {
420429
421430 // 3. Attribute values (highest precendence).
422431 if ( componentDefined ) {
423- if ( isSinglePropSchema ) { return parseProperty ( elData , schema ) ; }
432+ if ( isSinglePropSchema ) {
433+ if ( skipTypeChecking === true ) { return elData ; }
434+ return parseProperty ( elData , schema ) ;
435+ }
424436 data = extendProperties ( data , elData , isSinglePropSchema ) ;
425- return parseProperties ( data , schema , undefined , name , silent ) ;
426437 } else {
427- // Parse and coerce using the schema.
438+ if ( skipTypeChecking === true ) { return data ; }
439+ // Parse and coerce using the schema.
428440 if ( isSinglePropSchema ) { return parseProperty ( data , schema ) ; }
429- return parseProperties ( data , schema , undefined , name , silent ) ;
430441 }
442+
443+ if ( skipTypeChecking === true ) { return data ; }
444+ return parseProperties ( data , schema , undefined , name , silent ) ;
431445}
432446module . exports . buildData = buildData ;
433447
0 commit comments