Pinia scoped stores #2492
Unanswered
hassassin100
asked this question in
Help and Questions
Replies: 1 comment
-
I struggled with the exact same problem for a complex web app and it seems that Pinia does not offer a solution for this very real problem. I solved it by utilising Dependency Injection framework that offers |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, we're using Pinia at work and for our use cases so far, we have two types of stores.
This type of store is very straightforward to initialise. When multiple independent components use the store, we can guarantee that
getTestThingsApi
will be called once and consumers don't have to worry about calling afetch
action every time they use the store.Map
of things. E.g.This is okay, however our aim is to try and achieve the same goals we did with the 'global' store:
Map
data structure in the store itself.A proposal that came up to solve this was allowing for multiple instances of the same store (when constructing a 'scoped' store)
Here is a working example to demonstrate this.
Whilst it does make writing the store much easier and addresses our concerns, it seems like it deviates a little from the standard guidance we have seen in Pinia docco. In your opinion, is this valid use of Pinia? If not, would you recommend another way we could use Pinia to achieve the aforementioned goals? Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions