Type inconsistency
Closed this issue · 1 comments
I'm just looking through the library to make sense of it and see how I can apply the principals to my own project, and I noticed what seems to be a type inconsistency that TypeScript can't catch because it gets lost in Vuex dispatch and mutate methods.
I'm just going to think out loud to explain what I think I'm seeing. Please correct me if I'm wrong!
The Articles
service getAll()
seems to be responsible for creating the entity from the raw data, so when the fetchArticles
action is dispatched, the payload is an array of Article entities, which is then committed. But the state type for articles is for IArticlesData
, not IArticles
. Then the getter getAllArticles()
is duplicating the conversion, sending Article objects into the Article constructor. Since Articles and Comments inherit from their raw data types, this doesn't disrupt functionality or break any tests - it just makes your intentions a little bit confusing.
I figure there's a decent chance this is intentional and I'm missing something. What are your thoughts?
I'm bringing this up because I'm working with Cloud Firestore, and I'm trying to figure out a good pattern for denormalizing my data writes without making the code indecipherable, so my services have to update multiple records/raw data types for a single value change. Then, preserving one-way data flow, when data is written, the "snapshot" of new data from the server will be committed via a mutation. So I'm also trying to figure out the most sensible place to build my Entity objects from raw data, but also to update the entities when new data snapshots only present small changes. I'm inclined to build an entity object (or update it if it exists already) in the mutation and save it from there.
Ahh! Im so sorry, for some reason I didn't get notification about your message. My apologies, just saw this!
Yes, you are 100% right, that is my mistake. getAll should return flat data in our case or, at least, support a way for consumer to choose if they want to transform the data. I think however, Vuex flattens the result anyway, so getters do no idle work.
But anyway, I've update the source code so it should now reflect the proper way. Thank you so much for finding this 🙏