-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
What problem is this solving
- Eliminates boilerplate
createApp(...).use(createPinia())(common usage) orsetActivePinia(createPinia()) - Conceptually decouples Vue App instance from Pinia stores. You can use Pinia stores at any point... before or after Vue app creation.
- Faster bootstrapping for common usage pattern. If I am not mistaken, while more than one pinia instance can be instantiated, one pinia instance suffices and is the common usage pattern that is recommended.
- Eliminates the chicken and egg problems with up-front logic dependent on pinia stores that is ran prior to Vue App creation. (In my case, I have authentication-logic running in my main entry file before any other logic.)
- Allows for pattern where you can export single store instance using
defineStore({...})()without worries opposed to useStore functiondefineStore({...}). Makes consumption easier where I can skipuseStore()assignment to a local variable when I need to use the store instance in multiple places. - Author does not have to deal with
getActivePinia was called with no active Pinia. Did you forget to install pinia?issues again :)
Proposed solution
As part of defineStore options (3rd parameter), introduce some new setting (e.g. createActivePinia) which will create a Pinia instance (and set it active) if it does not exist at the time the store instance is created/retrieved via useStore(). Default setting to true.
Describe alternatives you've considered
- Same as proposed solution but default
createActivePiniasetting to false.