]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
chore: more tests
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 20 Jul 2021 17:06:47 +0000 (19:06 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 20 Jul 2021 17:06:47 +0000 (19:06 +0200)
playground/src/stores/jokes-swrv.ts
playground/src/views/swrv.vue

index 6f95b531d0531f99559ace124e585d47d3170407..376bdb54ea00b05d9b9cbe098408521717c3c5c5 100644 (file)
@@ -1,4 +1,4 @@
-import { ref, unref, watch } from 'vue'
+import { ref, toRaw, unref, watch } from 'vue'
 import { acceptHMRUpdate, defineStore } from '../../../src'
 import { getRandomJoke, Joke } from '../views/api/jokes'
 import useSWRV from 'swrv'
@@ -7,18 +7,16 @@ export const useJokesSetup = defineStore('jokes-swrv-setup', () => {
   // const current = ref<null | Joke>(null)
   const history = ref<Joke[]>([])
 
-  const { data, error, isValidating, mutate, revalidate } = useSWRV(
-    'jokes',
-    getRandomJoke
-  )
+  const { data, error, isValidating, mutate } = useSWRV('jokes', getRandomJoke)
 
   watch(data, (joke) => {
+    console.log('changed from within the store', joke)
     if (joke) {
-      history.value.push(joke)
+      history.value.push(toRaw(joke))
     }
   })
 
-  return { current: data, history, fetchJoke: revalidate }
+  return { current: data, error, history, fetchJoke: mutate }
 })
 
 if (import.meta.hot) {
index ca976375a58d7003c23c7433db715d06071b210f..98e63fd9623a77562c84cc0f38765fdd792f3913 100644 (file)
@@ -28,7 +28,7 @@
 </template>
 
 <script lang="ts" setup>
-import { computed, onMounted, ref } from 'vue'
+import { computed, onMounted, ref, watch } from 'vue'
 import { useJokesSetup } from '../stores/jokes-swrv'
 
 // const jokes = useJokes()
@@ -53,6 +53,13 @@ function fetchRandomJoke() {
   })
 }
 
+watch(
+  () => jokes.current,
+  (joke) => {
+    console.log('Got joke', joke)
+  }
+)
+
 onMounted(() => {
   console.log('mounted')
   // @ts-expect-error