Skip to content

Commit 3d3070a

Browse files
author
Scott Prue
committed
Fixed query bugs #2 and #3
* Fixes #3 (once query not working) * Fixes #2 (populate breaks if there is >0 queries) * Firebase version upped to v3.5.0
1 parent b0e9d03 commit 3d3070a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"react-redux-firebase"
6969
],
7070
"dependencies": {
71-
"firebase": "^3.4.1",
71+
"firebase": "^3.5.0",
7272
"immutable": "^3.8.1",
7373
"jwt-decode": "^2.1.0",
7474
"lodash": "^4.16.4"

src/actions/query.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ export const watchEvent = (firebase, dispatch, event, path, dest, onlyLastEvent
197197
}
198198

199199
const runQuery = (q, e, p, params) => {
200+
// Handle once queries
201+
if (e === 'once') {
202+
return q.once('value')
203+
.then(snapshot =>
204+
dispatch({ type: SET, path, data: snapshot.val() })
205+
)
206+
}
207+
208+
// Handle all other queries
200209
q.on(e, snapshot => {
201210
let data = (e === 'child_removed') ? undefined : snapshot.val()
202211
const resultPath = dest || (e === 'value') ? p : p + '/' + snapshot.key
@@ -208,8 +217,10 @@ export const watchEvent = (firebase, dispatch, event, path, dest, onlyLastEvent
208217
}
209218
}
210219

211-
const populates = filter(params, (param) => params.indexOf('populate'))
212-
.map(p => p.split('=')[1])
220+
// Get list of populates
221+
const populates = filter(params, param =>
222+
params.indexOf('populate') !== -1
223+
).map(p => p.split('=')[1])
213224

214225
// Dispatch standard if no populates
215226
if (!populates || !populates.length) {

0 commit comments

Comments
 (0)