From 749b32af3e0d682dc5db42cb3f4278d3b316d57f Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Sun, 17 May 2015 01:28:41 -0400 Subject: [PATCH] fix #36 by using DataSnapshot.forEach method to ensure array items are populated in order which query specifies --- src/reactfire.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/reactfire.js b/src/reactfire.js index 9bb1b9c5..fb344801 100644 --- a/src/reactfire.js +++ b/src/reactfire.js @@ -54,11 +54,17 @@ var ReactFireMixin = { this.firebaseRefs[bindVar] = firebaseRef.ref(); this.firebaseListeners[bindVar] = firebaseRef.on("value", function(dataSnapshot) { var newState = {}; + var data = {}; + + dataSnapshot.forEach(function(child) { + data[child.key()] = child.val(); + }); + if (bindAsArray) { - newState[bindVar] = this._toArray(dataSnapshot.val()); + newState[bindVar] = this._toArray(data); } else { - newState[bindVar] = dataSnapshot.val(); + newState[bindVar] = data; } this.setState(newState); }.bind(this), cancelCallback);