Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply removed sub-children on child changed #60

Merged
merged 1 commit into from
Jun 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions firebase-query.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@

__onFirebaseChildChanged: function(snapshot) {
var key = snapshot.key;
var value = this.__map[key];
var prev = this.__map[key];

this._log('Firebase child_changed:', key, value);
this._log('Firebase child_changed:', key, prev);

if (value) {
if (prev) {
this.async(function() {
var index = this.__indexFromKey(key);
value = snapshot.val();
var value = snapshot.val();
value.$key = key;
this.__map[key] = value;

Expand All @@ -332,6 +332,11 @@
for (var property in value) {
this.set(['data', index, property], value[property]);
}
for (var property in prev) {
if(!value.hasOwnProperty(property)) {
this.set(['data', index, property], undefined);
}
}
} else {
this.set(['data', index], value);
}
Expand Down
13 changes: 13 additions & 0 deletions test/firebase-query.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@
query.path + '/' + query.data[0].$key, query.data[0]);
});
});

test('removes sub-properties as they are removed from children', function() {
var object = makeObject();
object.foo = true;

return pushFirebaseValue(query.path, object).then(function() {
expect(query.data[0].foo).to.be.eql(true);
return setFirebaseValue(
query.path + '/' + query.data[0].$key + '/foo', null);
}).then(function() {
expect(query.data[0].foo).to.be.eql(undefined);
});
});
});

suite('coordinating with dom-repeat', function() {
Expand Down