Skip to content

Commit

Permalink
perf: simplify composable wrapper logic
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Oct 7, 2022
1 parent 225a235 commit 578d2d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 9 additions & 1 deletion playground/app.vue
Expand Up @@ -6,7 +6,15 @@ interface JsonPlaceholderPost {
body: string
}
const { data, refresh } = await useJsonPlaceholderData<JsonPlaceholderPost>('posts/1')
const { data, refresh } = await useJsonPlaceholderData<JsonPlaceholderPost>(
'posts/1',
{
async onResponse({ response }) {
// eslint-disable-next-line no-console
console.table(response._data)
},
},
)
</script>

<template>
Expand Down
8 changes: 2 additions & 6 deletions src/module.ts
Expand Up @@ -89,12 +89,8 @@ export default defineNuxtModule<ModuleOptions>({
return `
import { $api } from '${resolve('runtime/composables/$api')}'
import { useApiData } from '${resolve('runtime/composables/useApiData')}'
export function ${rawComposableName}(uri, opts = {}) {
return $api(uri, opts)
}
export function ${dataComposableName}(uri, opts = {}) {
return useApiData(uri, opts)
}
export const ${rawComposableName} = (...args) => $api(...args)
export const ${dataComposableName} = (...args) => useApiData(...args)
`.trimStart()
},
})
Expand Down

0 comments on commit 578d2d1

Please sign in to comment.