-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): add 'useQueriesState' composable (wip)
- Loading branch information
1 parent
78345fa
commit 25a237f
Showing
3 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { MaybeRefOrGetter } from 'vue' | ||
import { computed, toValue } from 'vue' | ||
import type { EntryKey } from './entry-options' | ||
import type { QueryStatus } from './query-store' | ||
import { useQueryCache } from './query-store' | ||
|
||
interface QueryState { | ||
data: unknown | ||
error: unknown | ||
status: QueryStatus | ||
} | ||
|
||
// TODO: accept also a since key (instead of an array) as argument | ||
// TODO: accept a ref for `keys` (to handle adding/removing entries for example)? | ||
export function useQueriesState(keys: Array<MaybeRefOrGetter<EntryKey>>) { | ||
const { ensureEntry } = useQueryCache() | ||
return computed(() => { | ||
return keys.map<QueryState[]>( | ||
// TODO: fix TS issue | ||
(key) => { | ||
const query = ensureEntry(toValue(key)) | ||
return { | ||
data: query.data.value, | ||
error: query.error.value, | ||
status: query.status.value, | ||
options: query.options, | ||
} | ||
}, | ||
) | ||
}) | ||
} |