-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(query): add useQueriesState
composable
#35
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add and use the |
||
return { | ||
data: query.data.value, | ||
error: query.error.value, | ||
status: query.status.value, | ||
options: query.options, | ||
} | ||
}, | ||
) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a query entry without options risks errors if the key is invalidated and the
options
are accessed. Probably, we should consider avoiding creating query entities inUseQueryState
and returnundefined/null
instead.