Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.
3 changes: 2 additions & 1 deletion firebase-database-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@
},

__pathChanged: function(path, oldPath) {
if (oldPath != null && !this.disabled && this.__pathReady(path)) {
if (!this.disabled && !this.valueIsEmpty(this.data)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also want to handle the case where path is not a valid one, but oldPath was.

this.syncToMemory(function() {
this.data = this.zeroValue;
this.__needSetData = true;
});
}
},
Expand Down
22 changes: 20 additions & 2 deletions firebase-document.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
],

attached: function() {
this.__needSetData = true;
this.__refChanged(this.ref, this.ref);
},

Expand Down Expand Up @@ -184,13 +185,30 @@

if (value == null) {
value = this.zeroValue;
this.__needSetData = true;
}

if (!this.new) {
if (!this.isNew) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be if (!this.isNew()) {?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNew is defined via its getter

    get isNew() {
      return this.disabled || !this.__pathReady(this.path);
    },

this.async(function() {
this.syncToMemory(function() {
this._log('Updating data from Firebase value:', value);
this.set('data', value);

// set the value if:
// it is the first time we run this (or the path has changed and we are back with zeroValue)
// or if this.data does not exist
// or value is primitive
// or if firebase value obj contain less keys than this.data (https://github.com/Polymer/polymer/issues/2565)
if (this.__needSetData || !this.data || typeof value !== 'object' || ( Object.keys(value).length < Object.keys(this.data).length)) {
this.__needSetData = false;
return this.set('data', value);
}

// now, we loop over keys
for (var prop in value) {
if(value[prop] !== this.data[prop]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be true for sub-objects, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it will - see my comment below for a short rationale

this.set(['data', prop], value[prop]);
}
}
});
});
}
Expand Down