Skip to content

Commit 2587be5

Browse files
committed
Merge pull request #57 from ktiedt/master
Fixes #55
2 parents f3ad6d2 + 6edf180 commit 2587be5

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

firebase-collection.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ <h4>[[dinosaur.__firebaseKey__]]</h4>
230230
'firebase-child-added': '_onFirebaseChildAdded',
231231
'firebase-child-removed': '_onFirebaseChildRemoved',
232232
'firebase-child-changed': '_onFirebaseChildChanged',
233-
'firebase-child-moved': '_onFirebaseChildChanged',
233+
'firebase-child-moved': '_onFirebaseChildMoved',
234234
},
235235

236236
/**
@@ -514,18 +514,22 @@ <h4>[[dinosaur.__firebaseKey__]]</h4>
514514
var value = this._valueMap[key];
515515
var previousChild;
516516
var newIndex;
517+
var currentIndex;
518+
var previousIndex;
517519

518520
if (!value) {
519521
this._error('Received firebase-child-moved event for unknown child "' + key + '"');
520522
return;
521523
}
522524

523-
previousValue = event.detail.previousChildName != null ?
525+
previousChild = event.detail.previousChildName != null ?
524526
this._valueMap[event.detail.previousChildName] : null;
525-
newIndex = previousValue != null ?
526-
this.data.indexOf(previousValue) + 1 : 0;
527527

528-
this.splice('data', this.data.indexOf(value), 1);
528+
currentIndex = this.data.indexOf(value);
529+
previousIndex = previousChild ? this.data.indexOf(previousChild) : -1;
530+
newIndex = currentIndex > previousIndex ? previousIndex + 1 : previousIndex;
531+
532+
this.splice('data', currentIndex, 1);
529533
this.splice('data', newIndex, 0, value);
530534
});
531535
}

firebase-query-behavior.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
},
145145

146146
_onQueryChildMoved: function(childSnapshot, previousChildName) {
147-
this._log('Firebase Event: "child_changed"', childSnapshot, previousChildName);
147+
this._log('Firebase Event: "child_moved"', childSnapshot, previousChildName);
148148
this.fire('firebase-child-moved', {
149149
childSnapshot: childSnapshot,
150150
previousChildName: previousChildName

0 commit comments

Comments
 (0)