forked from nuxtlabs/github-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithubRepository.ts
More file actions
32 lines (28 loc) · 854 Bytes
/
GithubRepository.ts
File metadata and controls
32 lines (28 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { defineComponent, useSlots, PropType } from 'vue'
import { hash } from 'ohash'
import { useGithub } from '../composables/useGithub'
import { GithubRepositoryOptions } from '../types'
// @ts-ignore
import { useAsyncData } from '#imports'
export default defineComponent({
props: {
query: {
type: Object as PropType<GithubRepositoryOptions>,
required: false,
default: () => ({})
}
},
async setup (props) {
const { fetchRepository } = useGithub()
const { data: repository, refresh, pending } = await useAsyncData(`github-repository-${hash(props.query)}`, () => fetchRepository(props.query))
return {
repository,
refresh,
pending
}
},
render ({ repository, refresh, pending }) {
const slots = useSlots()
return slots?.default?.({ repository, refresh, pending })
}
})