N
Nuxtβ€’8mo ago
Max Cahill

Layers: Knowing my layers

Hello friends! I am writing a little mono-repo multi-layered Nuxt3 project with Supabase. Doing so I already have few struggles I would like to address this wonderful community with: 1: Is there a way how to "manage" layers in runtime? (To give a the user a chance to turn the layer or/off)? My guess: Its not possible. 2: I would like every single layer to be able to register itself into application menu. That being said, it must be either able to perform certain operation (such as query the database) ONCE, when it was "used" (which seems impossible to me) OR I would need a way how to "loop" through all the layers I have in the project... Is there a way how to achieve this? 3: Can layers work with their "siblings" ? Example: I have a base layer - it extends layer UI and layer DB. Can I access layer DB from Layer UI without making layer UI extending layer DB? If I make (in this case) layer UI extend layer DB, wouldn't this "crash" the application due to DB layer being extended from base layer as well as from UI layer? 4: Namespacing - I know about this issue: https://github.com/nuxt/nuxt/issues/13367 - Named layers are about to come soon. But still I am interested in any advices or your experience, how do you guys distinguish between layers in code (preffixing components/composables/pages, ...)? 5: Store (i.e. Pinia): Do I understand it correctly it's a good practice to implement store (if possible) in the "lowest" module possible and then just use it in all sub-sequent layers? Any opinions are welcome here! Best regards, Max.
GitHub
Layers/Extends Support Tracker Β· Issue #13367 Β· nuxt/nuxt
Nuxt layers are a powerful feature that you can use to share and reuse partial Nuxt applications within a monorepo, or from a git repository or npm package. Docs: Usage: https://nuxt.com/docs/getti...
4 Replies
manniL
manniLβ€’8mo ago
1) No, but of course you could build that yourself 2) Not impossible but you'd have to build it yourself. You can define e.g. a custom Nuxt hook, register a plugin, use the app config etc. etc. 3) No, it is fine to have multiple layers extend a single one (so Base -> UI -> DB and Base -> DB) should work, as long a there is no cycle πŸ˜„ 4) I don't do at all. Sure, you can group things by feature in folders etc., but depending on your your layers can also mostly work "autonomously" 5) If you need stores in all apps which extend the lowest layer, yes
Max Cahill
Max CahillOPβ€’8mo ago
Many thanks @manniL / TheAlexLichter for clarification! Can you give me a little hint where to start at with point 1 - I have no clue at all πŸ™‚
manniL
manniLβ€’8mo ago
depends a lot on what your layer does I'm afraid πŸ™ˆ But as you technically can add/remove routes during runtime, and check the rest for components/pages etc., you could have some global state and check that, otherwise add/remove the routes and toggle components etc etc it is a very "bare-bone" implementation which you could also do without layers there is no real "mechanism" helping you there I'm afraid
Max Cahill
Max CahillOPβ€’8mo ago
I see, makes sense! Thank you very much!
Want results from more Discord servers?
Add your server