-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto Register stores dir in all layers #2757
base: v2
Are you sure you want to change the base?
Auto Register stores dir in all layers #2757
Conversation
✅ Deploy Preview for pinia-playground canceled.
|
✅ Deploy Preview for pinia-official ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
will this still register the stores dirs defined in layers if the main app defines it's own storesDirs? It seems like that null check would make it only apply the layers stores when the parent app sets it to null. |
No because The |
This looks very good; thanks for writing the patch. I was just hitting this layer issue. Why change the falsey check into a null check? If you want to keep it so, perhaps use
|
I made this wrapper module to work around this issue: https://gist.github.com/tommie/1e505f3f7a281698bdb9fdc7a303e6c0 |
Thank you
|
if (options.storesDirs == null) { | ||
// Add stores directory for each layer, including the main src dir | ||
options.storesDirs = [] | ||
for (const layer of nuxt.options._layers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a public API for layers. I don't know what it is but surely there must be a way to resolve the layers from the options, maybe with a nuxt hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nuxt.options._layers
seems to be the currently recommended solution for nuxt at present. There are two reasons:
- This solution is introduced in the nuxt documentation. refer: Multi-Layer Support for Nuxt Modules.
- In the nuxt source code, this api merging layer is also used. refer: https://github.com/nuxt/nuxt/blob/1c418d0ea3b046f2f7dedc3f39a87cc5be3e90b2/packages/nuxt/src/imports/module.ts#L62
@@ -6,6 +6,7 @@ const counter = useCounter() | |||
useTestStore() | |||
useSomeStoreStore() | |||
|
|||
const layerStore = useLayerStore() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not. I will need to take a proper look next time
Currently if user did not specify custom storesDir then the expected to auto import stores from stores dir but this is not working inside layers