What is the best way to update an object within a big list of object within the pinia store? #2590
Unanswered
Kroeg93
asked this question in
Help and Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently I'am using the pinia store for the first time and wonder what is the best way to update an object within the store from a component.
I tend to do the following:
I have a store with a nested list:
I'm using getter functions directly from store for getting the specific levels for rendering e.g. list views. But when I want to change an object within this list I am not sure what is the best way.
I tend to do it like that:
I'm writing a getter to get the specific object. After this I would define an reactiveState within the component (e.g. a details component for changing attributes like name, displayName, ...) and deepClone the object from store into my local component state. When i've done with updating i would replace the object within the store with the object from my component state.
Of course i could simply update the entry within the list directly without cloning the state, but I'm not sure about e.g. the performance: Doing it directly within the store, I would call the getter multiple times to fill the attributes to my textfields - so this calls everytime a filter function. Furthermore, everytime I would do some changes to the object I need to identify my object within the list again and then update it directly within the store which sounds also bad in terms of for performance for me.
Within my approach on the other side I have deepClone which is performance intensive I think and I also have the problem, that i need to replace the refering object within the list with my object from the component state.
Both approaches are maybe not ideal - so maybe there are other approaches?
I hope everything is understandable and I would be very happy to hear opinions on my approach!
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions