-
-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firestore Collection to map rather than list #685
Comments
You can create a computed that generates the object from the array. More information would be helpful to decide whether this feature is worth adding or not 🙂 |
I have a list of documents from a query, and I don't need the entire document in memory, just one of the ids is there a way to use serialize option to solve this? |
@posva |
I'm sure this would involve a major, breaking change since all the mutations are already based on arrays. But it's definitely better architecture for performance reasons too. Based on @posva, you could do a computed property like this: computed: {
assets: {
get(array) {
return array.reduce((obj, item) => {
obj[item.id] = item;
return obj;
}, {});
},
set(value) {
// covert back to array
this.$store.commit('SET_ASSETS', Object.values(value));
},
},
} It doesn't solve the performance issue since you're actually doing MORE computations, but will ensure:
|
Has there been any update to this? It is not just about a computed property. By not storing the collection as a map, I feel like we are not being true to how firestore stores these collections. In firestore, collection is not a list of documents rather it is a dictionary of ids mapped to specific documents. Because, this ends up being a generic list, it creates some interesting challenges when subcollections are being used. In my case, I have got a subcollection that is being loaded as each component mapped to a document from the parent collection loads. I need to store these subcollection somewhere mapped by the original collection id in the state. It has proven to be an unnecessary hassle thus far (and I have had do a bunch gymnastics to get it right). It would be great if this was changed. |
FYI if you're using lodash:
Though obviously building a |
I have a weaker case, but I'd like to also throw it out for discussion... Consider I have another type that references assets, such as
Today I would do this in 2 steps:
I think we could avoid the overhead of creating & storing the comments array if VueFire did the groupBy internally during snapshot parsing (similar to the OP's proposed change), eg: |
Is this the only feature request that got away from the #1241 Roadmap or is it still under consideration? I can see the Roadmap-issue is closed. When the data model does not imply an array, the above mentioned solution diminishes Vuefires sleekness and I find myself "manually" binding the collection without Vuefire. The withConverter() seems to wrap the results with an array in spite of returning an object. Best regards Morten |
I have the following binding from my Firestore collection to my state:
However this binds them to assets as a list, I.e.
Whereas I'd like it to be bound as a map like:
How could I go about achieving this?
The text was updated successfully, but these errors were encountered: