zoobzio
zoobzio
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
happy to help!
14 replies
NNuxt
Created by AxelSorensen on 10/24/2024 in #❓・help
Composables that depend on eachother
is there any issue w/ using clearNuxtData on logout? https://nuxt.com/docs/api/utils/clear-nuxt-data if the user logs back in during the same session, they would refetch any relevant data as they navigate just like they would on first page load because the data has been cleared I guess I don't understand a use case where page data would need to be refreshed on login outside of navigating back to that page, it makes more sense to treat a login action as a fresh application load & apply the same rules it's also really only relevant in situations where a user is logged in & opens a page, then logs out, then logs back in without reloading the app, then returns to a page expecting data to be present. far simpler to just make that very specific use case wait for their data again, no?
9 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
@larsmyrup inferring from the error message, it kinda looks like you are building your runtime dir into a dist dir when that may not be necessary anything in a runtime dir should be built as part of the consuming application & not before it is consumed, I generally opt to separate the runtime dir from my src module & add runtime to the package exports w/o any kind of build defined within runtime should be .ts files rather than .d.ts, Nuxt will build your runtime for you before performing the imports & you might see a change (technically you are building the same file twice rn, could be related to the problem) I can't say much more than that w/o actually troubleshooting, thats just a gut reaction from the information available to get a better look at the module structure I know works, you can take a look at this module which demonstrates the concept: https://github.com/zoobzio/ltrl/tree/main/packages/nuxt-ltrl it's not at all related to your module most likely, but it's a good demonstration of how to separate the module src that you need to build & the runtime code you want to be built by Nuxt
14 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
layers work like normal nuxt apps do, define your utils/components in the normal directories & auto imports work fantastic in your consuming app, you just extend the layer & you have access to all the exports that layer exposes w/o needing to explicitly import them using the @nuxt/kit functions
14 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
@Sybrn it kind of sounds like you are developing UI libraries as standalone Nuxt modules & are expecting the components you define in your module to behave in the same capacity as they would if you were defining them within a Nuxt application (i.e. auto-imports of types/utils within components defined in your module) this unfortunately will not work, auto-imports are made available to the Nuxt application as part of the build process which your modules are not subject to until they are used within the consuming application. this is why your imports are available in the app but not your module components for the most part this is intentional, components within modules should not rely on auto-imports to avoid type collisions & other nefarious gotcha's, I would recommend using explicit relative imports within a runtime directory not only as a solution to this problem but also as a general practice when developing any module consumed by a Nuxt app that isn't really a fun answer though, so you can get what you are looking for if you are willing to refactor your module into a nuxt layer, check it out: https://nuxt.com/docs/guide/going-further/layers
14 replies
NNuxt
Created by AxelSorensen on 10/24/2024 in #❓・help
Composables that depend on eachother
it sounds like there is a linear dependency between fetchEpisode and fetchSimilarEpisodes the simplest solution by far would be to combine the functions into a single useAsyncData wrapper that grabs both in sequence:
// ...
const ep = await getDoc(docRef);
if (ep.exists()) {
const eps = await getDocs(/* query here */);
return {
episode: { ep.id, ...ep.data(),
similarEpisodes: eps.docs.map(doc => doc.data())
}
}
// ...
// ...
const ep = await getDoc(docRef);
if (ep.exists()) {
const eps = await getDocs(/* query here */);
return {
episode: { ep.id, ...ep.data(),
similarEpisodes: eps.docs.map(doc => doc.data())
}
}
// ...
this is a rough example of what I mean, but in most cases you are better off providing a component a single entry point for useAsyncData that provides all of the objects needed, you will have a hard time if you try and compose data like that within the component itself as the component state will become a nightmare to manage
9 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
you probably want to be looking at addImportSources compsable to import specific types from a known file in the runtime dir: https://nuxt.com/docs/api/kit/autoimports#addimportssources if the types directory is full of types you want auto-imported, you can also use the addImportsDir composable: https://nuxt.com/docs/api/kit/autoimports#addimportsdir addTypeTemplate is used to define virtual modules that are created as part of the build process, if the type definitions already exist & you don't need to generate them you are better off using one of the first two
14 replies