@isograph/react 0.0.0-main-ce58404c → 0.0.0-main-85244746
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/reader.d.ts +4 -1
- package/dist/loadable-hooks/useClientSideDefer.d.ts +11 -5
- package/dist/loadable-hooks/useClientSideDefer.js +0 -1
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts +11 -5
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts +7 -4
- package/dist/loadable-hooks/useSkipLimitPagination.js +0 -1
- package/package.json +4 -4
- package/src/core/reader.ts +7 -3
- package/src/loadable-hooks/useClientSideDefer.ts +26 -13
- package/src/loadable-hooks/useImperativeLoadableField.ts +26 -9
- package/src/loadable-hooks/useSkipLimitPagination.ts +12 -6
package/dist/core/reader.d.ts
CHANGED
@@ -75,5 +75,8 @@ export type ReaderLoadableField = {
|
|
75
75
|
readonly entrypoint: IsographEntrypoint<any, any> | IsographEntrypointLoader<any, any>;
|
76
76
|
};
|
77
77
|
type StableId = string;
|
78
|
-
export type LoadableField<
|
78
|
+
export type LoadableField<TReadFromStore extends {
|
79
|
+
data: object;
|
80
|
+
parameters: object;
|
81
|
+
}, TResult, TProvidedArgs extends object = object> = (args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs> | void) => [StableId, Factory<FragmentReference<TReadFromStore, TResult>>];
|
79
82
|
export {};
|
@@ -1,8 +1,14 @@
|
|
1
|
-
import { FragmentReference } from '../core/FragmentReference';
|
1
|
+
import { ExtractParameters, FragmentReference } from '../core/FragmentReference';
|
2
2
|
import { LoadableField } from '../core/reader';
|
3
|
-
export declare function useClientSideDefer<
|
4
|
-
|
3
|
+
export declare function useClientSideDefer<TReadFromStore extends {
|
4
|
+
data: object;
|
5
|
+
parameters: object;
|
6
|
+
}, TResult>(loadableField: LoadableField<TReadFromStore, TResult>): {
|
7
|
+
fragmentReference: FragmentReference<TReadFromStore, TResult>;
|
5
8
|
};
|
6
|
-
export declare function useClientSideDefer<
|
7
|
-
|
9
|
+
export declare function useClientSideDefer<TReadFromStore extends {
|
10
|
+
data: object;
|
11
|
+
parameters: object;
|
12
|
+
}, TResult, TProvidedArgs extends object>(loadableField: LoadableField<TReadFromStore, TResult, TProvidedArgs>, args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs>): {
|
13
|
+
fragmentReference: FragmentReference<TReadFromStore, TResult>;
|
8
14
|
};
|
@@ -5,7 +5,6 @@ const IsographEnvironmentProvider_1 = require("../react/IsographEnvironmentProvi
|
|
5
5
|
const cache_1 = require("../core/cache");
|
6
6
|
const react_disposable_state_1 = require("@isograph/react-disposable-state");
|
7
7
|
function useClientSideDefer(loadableField, args) {
|
8
|
-
// @ts-expect-error args is missing iff it has the type void
|
9
8
|
const [id, loader] = loadableField(args);
|
10
9
|
const environment = (0, IsographEnvironmentProvider_1.useIsographEnvironment)();
|
11
10
|
const cache = (0, cache_1.getOrCreateItemInSuspenseCache)(environment, id, loader);
|
@@ -1,9 +1,15 @@
|
|
1
|
-
import { FragmentReference } from '../core/FragmentReference';
|
1
|
+
import { ExtractParameters, FragmentReference } from '../core/FragmentReference';
|
2
2
|
import { UnassignedState } from '@isograph/react-disposable-state';
|
3
3
|
import { LoadableField } from '../core/reader';
|
4
|
-
type UseImperativeLoadableFieldReturn<
|
5
|
-
|
6
|
-
|
4
|
+
type UseImperativeLoadableFieldReturn<TReadFromStore extends {
|
5
|
+
data: object;
|
6
|
+
parameters: object;
|
7
|
+
}, TResult, TProvidedArgs extends object> = {
|
8
|
+
fragmentReference: FragmentReference<TReadFromStore, TResult> | UnassignedState;
|
9
|
+
loadField: (args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs> | void) => void;
|
7
10
|
};
|
8
|
-
export declare function useImperativeLoadableField<
|
11
|
+
export declare function useImperativeLoadableField<TReadFromStore extends {
|
12
|
+
data: object;
|
13
|
+
parameters: object;
|
14
|
+
}, TResult, TProvidedArgs extends object>(loadableField: LoadableField<TReadFromStore, TResult, TProvidedArgs>): UseImperativeLoadableFieldReturn<TReadFromStore, TResult, TProvidedArgs>;
|
9
15
|
export {};
|
@@ -2,20 +2,23 @@ import { LoadableField } from '../core/reader';
|
|
2
2
|
import { FragmentReference } from '../core/FragmentReference';
|
3
3
|
type SkipOrLimit = 'skip' | 'limit';
|
4
4
|
type OmitSkipLimit<TArgs> = keyof Omit<TArgs, SkipOrLimit> extends never ? void | Record<string, never> : Omit<TArgs, SkipOrLimit>;
|
5
|
-
type UseSkipLimitReturnValue<
|
5
|
+
type UseSkipLimitReturnValue<TReadFromStore extends {
|
6
|
+
data: object;
|
7
|
+
parameters: object;
|
8
|
+
}, TArgs, TItem> = {
|
6
9
|
readonly kind: 'Complete';
|
7
10
|
readonly fetchMore: (args: OmitSkipLimit<TArgs>, count: number) => void;
|
8
11
|
readonly results: ReadonlyArray<TItem>;
|
9
12
|
} | {
|
10
13
|
readonly kind: 'Pending';
|
11
14
|
readonly results: ReadonlyArray<TItem>;
|
12
|
-
readonly pendingFragment: FragmentReference<
|
15
|
+
readonly pendingFragment: FragmentReference<TReadFromStore, ReadonlyArray<TItem>>;
|
13
16
|
};
|
14
17
|
export declare function useSkipLimitPagination<TArgs extends {
|
15
18
|
skip: number | void | null;
|
16
19
|
limit: number | void | null;
|
17
20
|
}, TItem, TReadFromStore extends {
|
18
|
-
parameters:
|
21
|
+
parameters: TArgs;
|
19
22
|
data: object;
|
20
|
-
}>(loadableField: LoadableField<
|
23
|
+
}>(loadableField: LoadableField<TReadFromStore, ReadonlyArray<TItem>>): UseSkipLimitReturnValue<TReadFromStore, TArgs, TItem>;
|
21
24
|
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@isograph/react",
|
3
|
-
"version": "0.0.0-main-
|
3
|
+
"version": "0.0.0-main-85244746",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"homepage": "https://isograph.dev",
|
6
6
|
"main": "dist/index.js",
|
@@ -17,9 +17,9 @@
|
|
17
17
|
"tsc": "tsc"
|
18
18
|
},
|
19
19
|
"dependencies": {
|
20
|
-
"@isograph/disposable-types": "0.0.0-main-
|
21
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
22
|
-
"@isograph/reference-counted-pointer": "0.0.0-main-
|
20
|
+
"@isograph/disposable-types": "0.0.0-main-85244746",
|
21
|
+
"@isograph/react-disposable-state": "0.0.0-main-85244746",
|
22
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-85244746"
|
23
23
|
},
|
24
24
|
"peerDependencies": {
|
25
25
|
"react": "18.2.0"
|
package/src/core/reader.ts
CHANGED
@@ -141,6 +141,10 @@ type StableId = string;
|
|
141
141
|
/// Passing TArgs to the LoadableField should be cheap and do no "actual" work,
|
142
142
|
/// except to stringify the args or whatnot. Calling the factory can be
|
143
143
|
/// expensive. For example, doing so will probably trigger a network request.
|
144
|
-
export type LoadableField<
|
145
|
-
|
146
|
-
|
144
|
+
export type LoadableField<
|
145
|
+
TReadFromStore extends { data: object; parameters: object },
|
146
|
+
TResult,
|
147
|
+
TProvidedArgs extends object = object,
|
148
|
+
> = (
|
149
|
+
args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs> | void,
|
150
|
+
) => [StableId, Factory<FragmentReference<TReadFromStore, TResult>>];
|
@@ -1,23 +1,36 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
ExtractParameters,
|
3
|
+
FragmentReference,
|
4
|
+
} from '../core/FragmentReference';
|
2
5
|
import { useIsographEnvironment } from '../react/IsographEnvironmentProvider';
|
3
6
|
import { getOrCreateItemInSuspenseCache } from '../core/cache';
|
4
7
|
import { useLazyDisposableState } from '@isograph/react-disposable-state';
|
5
8
|
import { LoadableField } from '../core/reader';
|
6
9
|
|
7
|
-
export function useClientSideDefer<
|
8
|
-
|
9
|
-
|
10
|
+
export function useClientSideDefer<
|
11
|
+
TReadFromStore extends { data: object; parameters: object },
|
12
|
+
TResult,
|
13
|
+
>(
|
14
|
+
loadableField: LoadableField<TReadFromStore, TResult>,
|
15
|
+
): { fragmentReference: FragmentReference<TReadFromStore, TResult> };
|
10
16
|
|
11
|
-
export function useClientSideDefer<
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
export function useClientSideDefer<
|
18
|
+
TReadFromStore extends { data: object; parameters: object },
|
19
|
+
TResult,
|
20
|
+
TProvidedArgs extends object,
|
21
|
+
>(
|
22
|
+
loadableField: LoadableField<TReadFromStore, TResult, TProvidedArgs>,
|
23
|
+
args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs>,
|
24
|
+
): { fragmentReference: FragmentReference<TReadFromStore, TResult> };
|
15
25
|
|
16
|
-
export function useClientSideDefer<
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
export function useClientSideDefer<
|
27
|
+
TReadFromStore extends { data: object; parameters: object },
|
28
|
+
TResult,
|
29
|
+
TProvidedArgs extends object,
|
30
|
+
>(
|
31
|
+
loadableField: LoadableField<TReadFromStore, TResult, TProvidedArgs>,
|
32
|
+
args?: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs>,
|
33
|
+
): { fragmentReference: FragmentReference<TReadFromStore, TResult> } {
|
21
34
|
const [id, loader] = loadableField(args);
|
22
35
|
const environment = useIsographEnvironment();
|
23
36
|
const cache = getOrCreateItemInSuspenseCache(environment, id, loader);
|
@@ -1,23 +1,40 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
ExtractParameters,
|
3
|
+
FragmentReference,
|
4
|
+
} from '../core/FragmentReference';
|
2
5
|
import {
|
3
6
|
UnassignedState,
|
4
7
|
useUpdatableDisposableState,
|
5
8
|
} from '@isograph/react-disposable-state';
|
6
9
|
import { LoadableField } from '../core/reader';
|
7
10
|
|
8
|
-
type UseImperativeLoadableFieldReturn<
|
9
|
-
|
10
|
-
|
11
|
+
type UseImperativeLoadableFieldReturn<
|
12
|
+
TReadFromStore extends { data: object; parameters: object },
|
13
|
+
TResult,
|
14
|
+
TProvidedArgs extends object,
|
15
|
+
> = {
|
16
|
+
fragmentReference:
|
17
|
+
| FragmentReference<TReadFromStore, TResult>
|
18
|
+
| UnassignedState;
|
19
|
+
loadField: (
|
20
|
+
args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs> | void,
|
21
|
+
) => void;
|
11
22
|
};
|
12
23
|
|
13
|
-
export function useImperativeLoadableField<
|
14
|
-
|
15
|
-
|
24
|
+
export function useImperativeLoadableField<
|
25
|
+
TReadFromStore extends { data: object; parameters: object },
|
26
|
+
TResult,
|
27
|
+
TProvidedArgs extends object,
|
28
|
+
>(
|
29
|
+
loadableField: LoadableField<TReadFromStore, TResult, TProvidedArgs>,
|
30
|
+
): UseImperativeLoadableFieldReturn<TReadFromStore, TResult, TProvidedArgs> {
|
16
31
|
const { state, setState } =
|
17
|
-
useUpdatableDisposableState<FragmentReference<
|
32
|
+
useUpdatableDisposableState<FragmentReference<TReadFromStore, TResult>>();
|
18
33
|
|
19
34
|
return {
|
20
|
-
loadField: (
|
35
|
+
loadField: (
|
36
|
+
args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs> | void,
|
37
|
+
) => {
|
21
38
|
const [_id, loader] = loadableField(args);
|
22
39
|
setState(loader());
|
23
40
|
},
|
@@ -23,7 +23,11 @@ type OmitSkipLimit<TArgs> = keyof Omit<TArgs, SkipOrLimit> extends never
|
|
23
23
|
? void | Record<string, never>
|
24
24
|
: Omit<TArgs, SkipOrLimit>;
|
25
25
|
|
26
|
-
type UseSkipLimitReturnValue<
|
26
|
+
type UseSkipLimitReturnValue<
|
27
|
+
TReadFromStore extends { data: object; parameters: object },
|
28
|
+
TArgs,
|
29
|
+
TItem,
|
30
|
+
> =
|
27
31
|
| {
|
28
32
|
readonly kind: 'Complete';
|
29
33
|
readonly fetchMore: (args: OmitSkipLimit<TArgs>, count: number) => void;
|
@@ -32,7 +36,10 @@ type UseSkipLimitReturnValue<TArgs, TItem> =
|
|
32
36
|
| {
|
33
37
|
readonly kind: 'Pending';
|
34
38
|
readonly results: ReadonlyArray<TItem>;
|
35
|
-
readonly pendingFragment: FragmentReference<
|
39
|
+
readonly pendingFragment: FragmentReference<
|
40
|
+
TReadFromStore,
|
41
|
+
ReadonlyArray<TItem>
|
42
|
+
>;
|
36
43
|
};
|
37
44
|
|
38
45
|
type ArrayFragmentReference<
|
@@ -68,10 +75,10 @@ export function useSkipLimitPagination<
|
|
68
75
|
limit: number | void | null;
|
69
76
|
},
|
70
77
|
TItem,
|
71
|
-
TReadFromStore extends { parameters:
|
78
|
+
TReadFromStore extends { parameters: TArgs; data: object },
|
72
79
|
>(
|
73
|
-
loadableField: LoadableField<
|
74
|
-
): UseSkipLimitReturnValue<TArgs, TItem> {
|
80
|
+
loadableField: LoadableField<TReadFromStore, ReadonlyArray<TItem>>,
|
81
|
+
): UseSkipLimitReturnValue<TReadFromStore, TArgs, TItem> {
|
75
82
|
const networkRequestOptions = {
|
76
83
|
suspendIfInFlight: true,
|
77
84
|
throwOnNetworkError: true,
|
@@ -169,7 +176,6 @@ export function useSkipLimitPagination<
|
|
169
176
|
}
|
170
177
|
return clonedRefCountedPointer;
|
171
178
|
});
|
172
|
-
// @ts-expect-error
|
173
179
|
clonedPointers.push(newPointer);
|
174
180
|
|
175
181
|
const totalItemCleanupPair: ItemCleanupPair<
|