Skip to content

Commit 95c98a4

Browse files
committed
chore: up colada
1 parent d5e358b commit 95c98a4

8 files changed

+48
-57
lines changed

examples/nuxt/colada.options.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { PiniaColadaOptions } from '@pinia/colada'
2+
3+
export default {
4+
// Options here
5+
} satisfies PiniaColadaOptions

examples/nuxt/nuxt.config.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
export default defineNuxtConfig({
22
devtools: { enabled: true },
33

4-
modules: ['@pinia/nuxt'],
4+
modules: [
5+
'@pinia/nuxt',
6+
'@pinia/colada-nuxt',
7+
],
58

69
experimental: {
710
typedPages: true,
811
},
912

1013
compatibilityDate: '2024-09-10',
11-
})
14+
})

examples/nuxt/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"preview": "nuxt preview"
88
},
99
"devDependencies": {
10+
"@pinia/colada-nuxt": "0.0.4",
1011
"@pinia/nuxt": "^0.9.0",
1112
"nuxt": "^3.15.3",
1213
"unplugin-vue-router": "workspace:*"

examples/nuxt/pages/users/[id].vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const route = useRoute('users-id')
3232
<template>
3333
<div>
3434
<h1>User {{ route.params.id }}</h1>
35-
<pre>{{ user }}</pre>
35+
<p>{{ user.name }}</p>
36+
<ClientOnly>
37+
<pre>{{ user }}</pre>
38+
</ClientOnly>
3639
</div>
3740
</template>

examples/nuxt/pages/users/colada-[userId].vue

+16-13
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,45 @@ export const useUserData = defineColadaLoader('users-colada-userId', {
1616
console.table(user)
1717
return user
1818
},
19-
// TODO: could display existing data
20-
// lazy: (to, from) => !from || to.name !== from.name,
19+
// can be flexible
20+
// lazy: (to, from) => !!(from && to.name === from.name),
2121
lazy: false,
2222
})
2323
</script>
2424

2525
<script setup lang="ts">
26-
defineOptions({
27-
__loaders: [useUserData],
28-
})
29-
30-
const { data: user, error, isLoading, refresh } = useUserData()
26+
const { state: user, isLoading, refresh, refetch } = useUserData()
3127
const route = useRoute('users-colada-userId')
3228
</script>
3329

3430
<template>
3531
<div>
32+
<button @click="refresh()">Refresh</button>
33+
<button @click="refetch()">Refetch</button>
34+
<hr />
35+
3636
<h1>User {{ route.params.userId }}</h1>
37-
<p v-if="error">An error ocurred: {{ error.message }}</p>
37+
<p v-if="user.error">An error ocurred: {{ user.error.message }}</p>
3838

3939
<!-- display both -->
40-
<h3>Display both</h3>
40+
<h3>Display all state</h3>
41+
4142
<p v-if="isLoading">Loading fresh data...</p>
42-
<pre v-if="user">{{ user }}</pre>
43+
<pre v-if="user.data">{{ user.data }}</pre>
4344

4445
<hr />
46+
4547
<h3>Display one of them</h3>
46-
<template v-if="user">
48+
49+
<template v-if="user.status === 'success'">
4750
<p v-if="isLoading">Loading fresh data...</p>
48-
<pre v-else>{{ user }}</pre>
51+
<pre v-else>{{ user.data }}</pre>
4952
</template>
5053
<template v-else>
5154
<p v-if="isLoading">Loading fresh data...</p>
5255
<div v-else>
5356
<p>Something went wrong...</p>
54-
<p v-if="error">{{ error }}</p>
57+
<p v-if="user.error">{{ user.error }}</p>
5558
<button @click="refresh()">Retry</button>
5659
</div>
5760
</template>

examples/nuxt/plugins/payload-plugin.ts

-31
This file was deleted.

examples/nuxt/plugins/pinia-colada.ts

-10
This file was deleted.

pnpm-lock.yaml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)