Skip to content

Commit 8dcfa7d

Browse files
author
Jacob Wenger
committed
Merge pull request #14 from danielmahal/patch-1
Allow multiple listeners for identical paths
2 parents 3202438 + a3ced1f commit 8dcfa7d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ReactFireMixin.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var ReactFireMixin = {
55
/* Initializes the Firebase binding refs array */
66
componentWillMount: function() {
77
this.firebaseRefs = {};
8+
this.firebaseListeners = {};
89
},
910

1011
/* Removes any remaining Firebase bindings */
@@ -47,7 +48,7 @@ var ReactFireMixin = {
4748
}
4849

4950
this.firebaseRefs[bindVar] = firebaseRef.ref();
50-
firebaseRef.on("value", function(dataSnapshot) {
51+
this.firebaseListeners[bindVar] = firebaseRef.on("value", function(dataSnapshot) {
5152
var newState = {};
5253
if (bindAsArray) {
5354
newState[bindVar] = this._toArray(dataSnapshot.val());
@@ -67,8 +68,9 @@ var ReactFireMixin = {
6768
throw new Error("unexpected value for bindVar. \"" + bindVar + "\" was either never bound or has already been unbound");
6869
}
6970

70-
this.firebaseRefs[bindVar].off("value");
71+
this.firebaseRefs[bindVar].off("value", this.firebaseListeners[bindVar]);
7172
delete this.firebaseRefs[bindVar];
73+
delete this.firebaseListeners[bindVar];
7274
},
7375

7476

@@ -122,4 +124,4 @@ var ReactFireMixin = {
122124
}
123125
return out;
124126
}
125-
};
127+
};

0 commit comments

Comments
 (0)