Nested reactive objects(hierarchy of objects, relations) in a pinia store #1993
Unanswered
chreniuc
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
Uh oh!
There was an error while loading. Please reload this page.
-
I was using composition API and I heard about Pinia and saw that it's the standard way and I switched over.
But I encountered multiple problems, one of them being that I couldn't have nested reactive objects inside a pinia store, in composition API I had the following structure of "stores":
Sites
class, which contains a member of typeArray<Site>
+ other properties and membersSite
is a class with contains a member of typeArray<Event>
+ a member of typeArray<Order>
+ other properties and membersEvent
is a class with members and methodsOrder
is a class with members and methodsIn this case I created the sites object like this:
ref(new Sites())
and it worked like a charm.I switched to Pinia(because it is advertised as the standard way and it also works with devtools) and I ended up creating different stores for each and manually loading the stores, without having links between them:
setup()
)siteStore
siteStore
The problem with this method, is that you need to make sure you call reset(using composition api, you also do not have access to
$reset
and you need to create a custom reset method) on all "child" stores. Eg, when thesiteStore
loads another site(on route change), you need to call reset on all children, eg:eventsStore
,ordersStore
which is also a headache, because you lose the cache of the previous site, so when you reopen that route, it has to call back the API...Is there really no other way to do it? A cleaner way..
Beta Was this translation helpful? Give feedback.
All reactions