posva / vuexfire

Check
https://github.com/vuejs/vuefire
MIT License
558 stars 49 forks source link

Pass a filtered ref to bindFirebaseRef #170

Closed hashinteractive closed 6 years ago

hashinteractive commented 6 years ago

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 6 years ago

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

hashinteractive commented 6 years ago

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