vuefire
vuefire copied to clipboard
Allow specifying which references are automatically bound to avoid right errors
Currently if a reference data type's depth is not more than maxRefDepth
then it is by default binded. Instead there should be a way to override default behavior and specify the keys of the fields which should be binded.
Will have to think about a convenient api to customize keys that works well with nested documents
I'm still reading vuefire internals, but I had some ideas
Dataset
There're two collections: people
and sabers
.
There's a document called "Luke" inside "people" collection. Its data looks like this:
{
name: 'Luke',
father: ref_to_darth_vader_doc,
saber: ref_to_saber_doc
}
Rules
I only want to retrieve father, cause my user can only read people collection, not saber
Ideas
1 - My first idea was to create an "exclude" option, where you pass the keys you want to exclude:
export default {
data () {
luke: null
},
methods: {
bindLuke () {
const options = {
excludeKeys: ['saber']
}
this.$bind('luke', database.collection('people').doc(lukeId), options)
}
}
}
2 - Passing only keys is easier, but when handling subcollections this solution is not scalable. Maybe if we filter it by which document the reference is referring to it becomes better.
For instance, we can use wildcards just like firebase rules to exclude entire collections from the binding:
const options = {
excludePaths: ['sabers/{saberId}']
}
This second option only works if we want to exclude the ref cause the user doesn't have access to it. But if we want to exclude the ref loading cause it's too large or any other reason it becomes hard to select which keys to keep, cause the document might contain different keys referring to the same collection.
3 - So, my third idea is to use the wildcards syntax but for the keys path, not collections path:
const options = {
excludePaths: ['people/[wildcard or luke id]/saber']
}
4 - Maybe it could work without wildcards, but with references. But the implementation is not very clear to me:
const options = {
exclude: [{ collection: database.collection('people'), key: 'saber' }]
}
// or even
const options = {
exclude: [{ collection: 'people', key: 'saber' }]
}
What's the progress of this?
I came here to suggest this, but found it's been suggested. It seems like it wouldn't be very hard to do - I may even give it a shot. But before I dig in, does anyone know if this is already being considered or worked on for the next version?