posva/vuexfire

Pass a filtered ref to bindFirebaseRef

hashinteractive opened this issue · 2 comments

If you try to pass a filtered reference to bindFirebaseRef it still returns all of the objects at that node. For example:
const ref = app.$firebase.database().ref("/vendors").orderByChild("category/fitness").equalTo(true)
Should only return vendors in "fitness" category but it binds all vendors.

It would be nice if you could pass a filtered ref into the bindFirebaseRef function.

posva commented

This already works, as you can imagine vuexfire is fed with Firebase data so there's probably something not working in your filter. If you find out plain firebase is yielding different results, please provide a repro because it would be a bug

Hmm yeah it wasn't working for me so I'll see if I can reproduce. I even did the same with just:

app.$firebase.database().ref("/vendors").orderByChild("category/fitness").equalTo(true).on('value', (snap) => {
  console.log(snap.val())
  //was working as expected and returning filtered results
})

but if I did this...

const ref = app.$firebase.database().ref("/vendors").orderByChild("category/fitness").equalTo(true)
store.dispatch('setAllVendors', ref)

//vuex store
actions:{
setAllVendors: firebaseAction(({bindFirebaseRef}, {ref}) => {
        bindFirebaseRef('allVendors', ref) 
 })
}

//component
console.log(this.$store.state.allVendors)
//logs all the vendors that would be returned from app.$firebase.database().ref("/vendors") not the filtered vendors