Skip to content

Commit

Permalink
feat(api): allow watching options in useQuery (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Feb 6, 2024
1 parent 690c35f commit 3a5e808
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/composables/Api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Ref, ref } from 'vue'
import { type Ref, type WatchSource, ref, watch } from 'vue'
import { Http } from '../http/Http'
import { tryOnMounted } from './Utils'

Expand All @@ -14,6 +14,10 @@ export interface UseQueryOptions {
* @default true
*/
immediate?: boolean
/**
* watch the given source(s) and re-execute the query
*/
watch?: WatchSource | WatchSource[]
}

export interface Mutation<Data = any, Args extends any[] = any[]> {
Expand All @@ -35,6 +39,10 @@ export function useQuery<Data = any>(
tryOnMounted(execute)
}

if (options.watch) {
watch(options.watch, execute, { deep: true })
}

async function execute(): Promise<Data> {
loading.value = true

Expand Down

0 comments on commit 3a5e808

Please sign in to comment.