Skip to content

Commit

Permalink
refactor: generic type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Oct 21, 2024
1 parent f931aad commit a3c3206
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/friendly-donuts-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@reactive-dot/react": patch
"@reactive-dot/vue": patch
---

Refactored generic type parameters for chain IDs & descriptors.
10 changes: 6 additions & 4 deletions packages/react/src/hooks/use-query-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export function useQueryLoader() {
const _loadQuery = useCallback(
(get: Getter) =>
<
TQuery extends (
builder: Query<[], TDescriptor>,
) => Query<QueryInstruction<TDescriptor>[], TDescriptor>,
TDescriptor extends ChainDescriptorOf<TChainId>,
TChainId extends ChainId | undefined,
TQuery extends (
builder: Query<[], ChainDescriptorOf<TChainId>>,
) => Query<
QueryInstruction<ChainDescriptorOf<TChainId>>[],
ChainDescriptorOf<TChainId>
>,
>(
builder: TQuery,
options?: ChainHookOptions<TChainId>,
Expand Down
12 changes: 8 additions & 4 deletions packages/react/src/hooks/use-query-refresher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ import { useCallback } from "react";
* @returns The function to refresh the query
*/
export function useQueryRefresher<
TChainId extends ChainId | undefined,
TQuery extends
| ((
builder: Query<[], TDescriptor>,
) => Query<QueryInstruction<TDescriptor>[], TDescriptor> | Falsy)
builder: Query<[], ChainDescriptorOf<TChainId>>,
) =>
| Query<
QueryInstruction<ChainDescriptorOf<TChainId>>[],
ChainDescriptorOf<TChainId>
>
| Falsy)
| Falsy,
TDescriptor extends ChainDescriptorOf<TChainId>,
TChainId extends ChainId | undefined,
>(builder: TQuery, options?: ChainHookOptions<TChainId>) {
const config = useConfig();
const chainId = internal_useChainId(options);
Expand Down
22 changes: 15 additions & 7 deletions packages/react/src/hooks/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import { useMemo } from "react";
* @returns The data response
*/
export function useLazyLoadQuery<
TChainId extends ChainId | undefined,
TQuery extends
| ((
builder: Query<[], TDescriptor>,
) => Query<QueryInstruction<TDescriptor>[], TDescriptor> | Falsy)
builder: Query<[], ChainDescriptorOf<TChainId>>,
) =>
| Query<
QueryInstruction<ChainDescriptorOf<TChainId>>[],
ChainDescriptorOf<TChainId>
>
| Falsy)
| Falsy,
TDescriptor extends ChainDescriptorOf<TChainId>,
TChainId extends ChainId | undefined,
>(builder: TQuery, options?: ChainHookOptions<TChainId>) {
const config = useConfig();
const chainId = internal_useChainId(options);
Expand Down Expand Up @@ -86,10 +90,14 @@ export function useLazyLoadQuery<
export function useLazyLoadQueryWithRefresh<
TQuery extends
| ((
builder: Query<[], TDescriptor>,
) => Query<QueryInstruction<TDescriptor>[], TDescriptor> | Falsy)
builder: Query<[], ChainDescriptorOf<TChainId>>,
) =>
| Query<
QueryInstruction<ChainDescriptorOf<TChainId>>[],
ChainDescriptorOf<TChainId>
>
| Falsy)
| Falsy,
TDescriptor extends ChainDescriptorOf<TChainId>,
TChainId extends ChainId | undefined,
>(builder: TQuery, options?: ChainHookOptions<TChainId>) {
const data = useLazyLoadQuery(builder, options);
Expand Down
12 changes: 8 additions & 4 deletions packages/vue/src/composables/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ import {
* @returns The data response
*/
export function useQuery<
TQuery extends (
builder: Query<[], TDescriptor>,
) => Query<QueryInstruction<TDescriptor>[], TDescriptor> | Falsy,
TDescriptor extends ChainDescriptorOf<TChainId>,
TChainId extends ChainId | undefined,
TQuery extends (
builder: Query<[], ChainDescriptorOf<TChainId>>,
) =>
| Query<
QueryInstruction<ChainDescriptorOf<TChainId>>[],
ChainDescriptorOf<TChainId>
>
| Falsy,
>(builder: TQuery, options?: ChainComposableOptions<TChainId>) {
const chainId = internal_useChainId(options);
const typedApiPromise = useTypedApiPromise(options);
Expand Down

0 comments on commit a3c3206

Please sign in to comment.