@khanacademy/wonder-blocks-data 10.1.0 → 10.1.2
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/CHANGELOG.md +31 -0
- package/dist/components/data.d.ts +52 -0
- package/dist/components/data.js.flow +63 -0
- package/dist/components/gql-router.d.ts +24 -0
- package/dist/components/gql-router.js.flow +33 -0
- package/dist/components/intercept-context.d.ts +10 -0
- package/dist/components/intercept-context.js.flow +19 -0
- package/dist/components/intercept-requests.d.ts +42 -0
- package/dist/components/intercept-requests.js.flow +51 -0
- package/dist/components/track-data.d.ts +11 -0
- package/dist/components/track-data.js.flow +18 -0
- package/dist/es/index.js +184 -212
- package/dist/hooks/use-cached-effect.d.ts +70 -0
- package/dist/hooks/use-cached-effect.js.flow +85 -0
- package/dist/hooks/use-gql-router-context.d.ts +5 -0
- package/dist/hooks/use-gql-router-context.js.flow +15 -0
- package/dist/hooks/use-gql.d.ts +12 -0
- package/dist/hooks/use-gql.js.flow +29 -0
- package/dist/hooks/use-hydratable-effect.d.ts +102 -0
- package/dist/hooks/use-hydratable-effect.js.flow +125 -0
- package/dist/hooks/use-request-interception.d.ts +14 -0
- package/dist/hooks/use-request-interception.js.flow +25 -0
- package/dist/hooks/use-server-effect.d.ts +39 -0
- package/dist/hooks/use-server-effect.js.flow +51 -0
- package/dist/hooks/use-shared-cache.d.ts +32 -0
- package/dist/hooks/use-shared-cache.js.flow +43 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +186 -217
- package/dist/index.js.flow +48 -2
- package/dist/util/data-error.d.ts +45 -0
- package/dist/util/data-error.js.flow +64 -0
- package/dist/util/get-gql-data-from-response.d.ts +4 -0
- package/dist/util/get-gql-data-from-response.js.flow +13 -0
- package/dist/util/get-gql-request-id.d.ts +5 -0
- package/dist/util/get-gql-request-id.js.flow +20 -0
- package/dist/util/gql-error.d.ts +28 -0
- package/dist/util/gql-error.js.flow +43 -0
- package/dist/util/gql-router-context.d.ts +3 -0
- package/dist/util/gql-router-context.js.flow +10 -0
- package/dist/util/gql-types.d.ts +34 -0
- package/dist/util/gql-types.js.flow +53 -0
- package/dist/util/graphql-document-node-parser.d.ts +18 -0
- package/dist/util/graphql-document-node-parser.js.flow +31 -0
- package/dist/util/graphql-types.d.ts +19 -0
- package/dist/util/graphql-types.js.flow +30 -0
- package/dist/util/hydration-cache-api.d.ts +17 -0
- package/dist/util/hydration-cache-api.js.flow +30 -0
- package/dist/util/merge-gql-context.d.ts +8 -0
- package/dist/util/merge-gql-context.js.flow +19 -0
- package/dist/util/purge-caches.d.ts +8 -0
- package/dist/util/purge-caches.js.flow +15 -0
- package/dist/util/request-api.d.ts +28 -0
- package/dist/util/request-api.js.flow +34 -0
- package/dist/util/request-fulfillment.d.ts +37 -0
- package/dist/util/request-fulfillment.js.flow +50 -0
- package/dist/util/request-tracking.d.ts +62 -0
- package/dist/util/request-tracking.js.flow +81 -0
- package/dist/util/result-from-cache-response.d.ts +5 -0
- package/dist/util/result-from-cache-response.js.flow +15 -0
- package/dist/util/scoped-in-memory-cache.d.ts +38 -0
- package/dist/util/scoped-in-memory-cache.js.flow +57 -0
- package/dist/util/serializable-in-memory-cache.d.ts +16 -0
- package/dist/util/serializable-in-memory-cache.js.flow +26 -0
- package/dist/util/ssr-cache.d.ts +51 -0
- package/dist/util/ssr-cache.js.flow +87 -0
- package/dist/util/status.d.ts +10 -0
- package/dist/util/status.js.flow +19 -0
- package/dist/util/to-gql-operation.d.ts +32 -0
- package/dist/util/to-gql-operation.js.flow +45 -0
- package/dist/util/types.d.ts +111 -0
- package/dist/util/types.js.flow +151 -0
- package/package.json +5 -6
- package/src/components/__tests__/{data.test.js → data.test.tsx} +42 -2
- package/src/components/__tests__/{gql-router.test.js → gql-router.test.tsx} +4 -5
- package/src/components/__tests__/{intercept-requests.test.js → intercept-requests.test.tsx} +2 -3
- package/src/components/__tests__/{track-data.test.js → track-data.test.tsx} +2 -3
- package/src/components/{data.js → data.ts} +11 -15
- package/src/components/{gql-router.js → gql-router.tsx} +12 -14
- package/src/components/{intercept-context.js → intercept-context.ts} +4 -3
- package/src/components/{intercept-requests.js → intercept-requests.tsx} +7 -8
- package/src/components/{track-data.js → track-data.tsx} +4 -5
- package/src/hooks/__tests__/{use-cached-effect.test.js → use-cached-effect.test.tsx} +55 -50
- package/src/hooks/__tests__/{use-gql-router-context.test.js → use-gql-router-context.test.tsx} +7 -7
- package/src/hooks/__tests__/{use-gql.test.js → use-gql.test.tsx} +20 -21
- package/src/hooks/__tests__/{use-hydratable-effect.test.js → use-hydratable-effect.test.ts} +42 -37
- package/src/hooks/__tests__/{use-request-interception.test.js → use-request-interception.test.tsx} +5 -3
- package/src/hooks/__tests__/{use-server-effect.test.js → use-server-effect.test.ts} +8 -2
- package/src/hooks/__tests__/{use-shared-cache.test.js → use-shared-cache.test.ts} +12 -12
- package/src/hooks/{use-cached-effect.js → use-cached-effect.ts} +27 -20
- package/src/hooks/{use-gql-router-context.js → use-gql-router-context.ts} +2 -3
- package/src/hooks/{use-gql.js → use-gql.ts} +5 -5
- package/src/hooks/{use-hydratable-effect.js → use-hydratable-effect.ts} +53 -58
- package/src/hooks/{use-request-interception.js → use-request-interception.ts} +4 -4
- package/src/hooks/{use-server-effect.js → use-server-effect.ts} +7 -9
- package/src/hooks/{use-shared-cache.js → use-shared-cache.ts} +13 -8
- package/src/{index.js → index.ts} +0 -1
- package/src/util/__tests__/{get-gql-data-from-response.test.js → get-gql-data-from-response.test.ts} +0 -1
- package/src/util/__tests__/{get-gql-request-id.test.js → get-gql-request-id.test.ts} +9 -11
- package/src/util/__tests__/{graphql-document-node-parser.test.js → graphql-document-node-parser.test.ts} +11 -12
- package/src/util/__tests__/{hydration-cache-api.test.js → hydration-cache-api.test.ts} +1 -2
- package/src/util/__tests__/{merge-gql-context.test.js → merge-gql-context.test.ts} +4 -5
- package/src/util/__tests__/{purge-caches.test.js → purge-caches.test.ts} +0 -1
- package/src/util/__tests__/{request-api.test.js → request-api.test.ts} +2 -2
- package/src/util/__tests__/{request-fulfillment.test.js → request-fulfillment.test.ts} +0 -1
- package/src/util/__tests__/{request-tracking.test.js → request-tracking.test.tsx} +13 -6
- package/src/util/__tests__/{result-from-cache-response.test.js → result-from-cache-response.test.ts} +2 -4
- package/src/util/__tests__/{scoped-in-memory-cache.test.js → scoped-in-memory-cache.test.ts} +4 -5
- package/src/util/__tests__/{serializable-in-memory-cache.test.js → serializable-in-memory-cache.test.ts} +7 -7
- package/src/util/__tests__/{ssr-cache.test.js → ssr-cache.test.ts} +3 -2
- package/src/util/__tests__/{to-gql-operation.test.js → to-gql-operation.test.ts} +2 -1
- package/src/util/{data-error.js → data-error.ts} +2 -3
- package/src/util/{get-gql-data-from-response.js → get-gql-data-from-response.ts} +1 -6
- package/src/util/{get-gql-request-id.js → get-gql-request-id.ts} +12 -16
- package/src/util/{gql-error.js → gql-error.ts} +2 -3
- package/src/util/gql-router-context.ts +6 -0
- package/src/util/{gql-types.js → gql-types.ts} +27 -23
- package/src/util/{graphql-document-node-parser.js → graphql-document-node-parser.ts} +6 -7
- package/src/util/graphql-types.ts +27 -0
- package/src/util/{hydration-cache-api.js → hydration-cache-api.ts} +4 -2
- package/src/util/{merge-gql-context.js → merge-gql-context.ts} +2 -2
- package/src/util/{purge-caches.js → purge-caches.ts} +0 -1
- package/src/util/{request-api.js → request-api.ts} +0 -1
- package/src/util/{request-fulfillment.js → request-fulfillment.ts} +13 -12
- package/src/util/{request-tracking.js → request-tracking.ts} +12 -13
- package/src/util/{result-from-cache-response.js → result-from-cache-response.ts} +3 -4
- package/src/util/{scoped-in-memory-cache.js → scoped-in-memory-cache.ts} +1 -2
- package/src/util/{serializable-in-memory-cache.js → serializable-in-memory-cache.ts} +2 -3
- package/src/util/{ssr-cache.js → ssr-cache.ts} +19 -18
- package/src/util/{status.js → status.ts} +4 -5
- package/src/util/{to-gql-operation.js → to-gql-operation.ts} +1 -2
- package/src/util/{types.js → types.ts} +39 -48
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -18
- package/src/__docs__/_overview_graphql.stories.mdx +0 -35
- package/src/__docs__/_overview_ssr_.stories.mdx +0 -185
- package/src/__docs__/_overview_testing_.stories.mdx +0 -123
- package/src/__docs__/exports.abort-inflight-requests.stories.mdx +0 -20
- package/src/__docs__/exports.data-error.stories.mdx +0 -23
- package/src/__docs__/exports.data-errors.stories.mdx +0 -23
- package/src/__docs__/exports.data.stories.mdx +0 -146
- package/src/__docs__/exports.fetch-tracked-requests.stories.mdx +0 -24
- package/src/__docs__/exports.get-gql-request-id.stories.mdx +0 -24
- package/src/__docs__/exports.gql-error.stories.mdx +0 -23
- package/src/__docs__/exports.gql-errors.stories.mdx +0 -20
- package/src/__docs__/exports.gql-router.stories.mdx +0 -29
- package/src/__docs__/exports.has-tracked-requests-to-be-fetched.stories.mdx +0 -20
- package/src/__docs__/exports.intercept-requests.stories.mdx +0 -69
- package/src/__docs__/exports.intialize-hydration-cache.stories.mdx +0 -29
- package/src/__docs__/exports.purge-caches.stories.mdx +0 -23
- package/src/__docs__/exports.purge-hydration-cache.stories.mdx +0 -24
- package/src/__docs__/exports.scoped-in-memory-cache.stories.mdx +0 -92
- package/src/__docs__/exports.serializable-in-memory-cache.stories.mdx +0 -112
- package/src/__docs__/exports.shared-cache.stories.mdx +0 -16
- package/src/__docs__/exports.status.stories.mdx +0 -31
- package/src/__docs__/exports.track-data.stories.mdx +0 -209
- package/src/__docs__/exports.use-cached-effect.stories.mdx +0 -44
- package/src/__docs__/exports.use-gql.stories.mdx +0 -41
- package/src/__docs__/exports.use-hydratable-effect.stories.mdx +0 -43
- package/src/__docs__/exports.use-server-effect.stories.mdx +0 -50
- package/src/__docs__/exports.use-shared-cache.stories.mdx +0 -30
- package/src/__docs__/exports.when-client-side.stories.mdx +0 -33
- package/src/__docs__/types.cached-response.stories.mdx +0 -29
- package/src/__docs__/types.error-options.stories.mdx +0 -21
- package/src/__docs__/types.fetch-policy.stories.mdx +0 -44
- package/src/__docs__/types.gql-context.stories.mdx +0 -20
- package/src/__docs__/types.gql-fetch-fn.stories.mdx +0 -24
- package/src/__docs__/types.gql-fetch-options.stories.mdx +0 -24
- package/src/__docs__/types.gql-operation-type.stories.mdx +0 -24
- package/src/__docs__/types.gql-operation.stories.mdx +0 -67
- package/src/__docs__/types.raw-scoped-cache.stories.mdx +0 -27
- package/src/__docs__/types.response-cache.stories.mdx +0 -33
- package/src/__docs__/types.result.stories.mdx +0 -39
- package/src/__docs__/types.scoped-cache.stories.mdx +0 -114
- package/src/__docs__/types.valid-cache-data.stories.mdx +0 -23
- package/src/util/gql-router-context.js +0 -6
- package/src/util/graphql-types.js +0 -30
- /package/src/hooks/__tests__/__snapshots__/{use-shared-cache.test.js.snap → use-shared-cache.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{scoped-in-memory-cache.test.js.snap → scoped-in-memory-cache.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{serializable-in-memory-cache.test.js.snap → serializable-in-memory-cache.test.ts.snap} +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
2
|
+
import { FetchPolicy } from "../util/types";
|
|
3
|
+
type CachedEffectOptions<TData extends ValidCacheData> = {
|
|
4
|
+
/**
|
|
5
|
+
* The policy to use when determining how to retrieve the request data from
|
|
6
|
+
* cache and network.
|
|
7
|
+
*
|
|
8
|
+
* Defaults to `FetchPolicy.CacheBeforeNetwork`.
|
|
9
|
+
*/
|
|
10
|
+
fetchPolicy?: typeof FetchPolicy[keyof typeof FetchPolicy];
|
|
11
|
+
/**
|
|
12
|
+
* When `true`, the effect will not be executed; otherwise, the effect will
|
|
13
|
+
* be executed.
|
|
14
|
+
*
|
|
15
|
+
* If this is set to `true` while the effect is still pending, the pending
|
|
16
|
+
* effect will be cancelled.
|
|
17
|
+
*
|
|
18
|
+
* Default is `false`.
|
|
19
|
+
*/
|
|
20
|
+
skip?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* When `true`, the effect will not reset the result to the loading status
|
|
23
|
+
* while executing if the requestId changes, instead, returning
|
|
24
|
+
* the existing result from before the change; otherwise, the result will
|
|
25
|
+
* be set to loading status.
|
|
26
|
+
*
|
|
27
|
+
* If the status is loading when the changes are made, it will remain as
|
|
28
|
+
* loading; old pending effects are discarded on changes and as such this
|
|
29
|
+
* value has no effect in that case.
|
|
30
|
+
*/
|
|
31
|
+
retainResultOnChange?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Callback that is invoked if the result for the given hook has changed.
|
|
34
|
+
*
|
|
35
|
+
* When defined, the hook will invoke this callback whenever it has reason
|
|
36
|
+
* to change the result and will not otherwise affect component rendering
|
|
37
|
+
* directly.
|
|
38
|
+
*
|
|
39
|
+
* When not defined, the hook will ensure the component re-renders to pick
|
|
40
|
+
* up the latest result.
|
|
41
|
+
*/
|
|
42
|
+
onResultChanged?: (result: Result<TData>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Scope to use with the shared cache.
|
|
45
|
+
*
|
|
46
|
+
* When specified, the given scope will be used to isolate this hook's
|
|
47
|
+
* cached results. Otherwise, a shared default scope will be used.
|
|
48
|
+
*
|
|
49
|
+
* Changing this value after the first call is not supported.
|
|
50
|
+
*/
|
|
51
|
+
scope?: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Hook to execute and cache an async operation on the client.
|
|
55
|
+
*
|
|
56
|
+
* This hook executes the given handler on the client if there is no
|
|
57
|
+
* cached result to use.
|
|
58
|
+
*
|
|
59
|
+
* Results are cached so they can be shared between equivalent invocations.
|
|
60
|
+
* In-flight requests are also shared, so that concurrent calls will
|
|
61
|
+
* behave as one might exect. Cache updates invoked by one hook instance
|
|
62
|
+
* do not trigger renders in components that use the same requestID; however,
|
|
63
|
+
* that should not matter since concurrent requests will share the same
|
|
64
|
+
* in-flight request, and subsequent renders will grab from the cache.
|
|
65
|
+
*
|
|
66
|
+
* Once the request has been tried once and a non-loading response has been
|
|
67
|
+
* cached, the request will not executed made again.
|
|
68
|
+
*/
|
|
69
|
+
export declare const useCachedEffect: <TData extends ValidCacheData>(requestId: string, handler: () => Promise<TData>, options?: CachedEffectOptions<TData>) => [Result<TData>, () => void];
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-cached-effect
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
9
|
+
import { FetchPolicy } from "../util/types";
|
|
10
|
+
declare type CachedEffectOptions<TData: ValidCacheData> = {
|
|
11
|
+
/**
|
|
12
|
+
* The policy to use when determining how to retrieve the request data from
|
|
13
|
+
* cache and network.
|
|
14
|
+
*
|
|
15
|
+
* Defaults to `FetchPolicy.CacheBeforeNetwork`.
|
|
16
|
+
*/
|
|
17
|
+
fetchPolicy?: $ElementType<typeof FetchPolicy, $Keys<typeof FetchPolicy>>,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* When `true`, the effect will not be executed; otherwise, the effect will
|
|
21
|
+
* be executed.
|
|
22
|
+
*
|
|
23
|
+
* If this is set to `true` while the effect is still pending, the pending
|
|
24
|
+
* effect will be cancelled.
|
|
25
|
+
*
|
|
26
|
+
* Default is `false`.
|
|
27
|
+
*/
|
|
28
|
+
skip?: boolean,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* When `true`, the effect will not reset the result to the loading status
|
|
32
|
+
* while executing if the requestId changes, instead, returning
|
|
33
|
+
* the existing result from before the change; otherwise, the result will
|
|
34
|
+
* be set to loading status.
|
|
35
|
+
*
|
|
36
|
+
* If the status is loading when the changes are made, it will remain as
|
|
37
|
+
* loading; old pending effects are discarded on changes and as such this
|
|
38
|
+
* value has no effect in that case.
|
|
39
|
+
*/
|
|
40
|
+
retainResultOnChange?: boolean,
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Callback that is invoked if the result for the given hook has changed.
|
|
44
|
+
*
|
|
45
|
+
* When defined, the hook will invoke this callback whenever it has reason
|
|
46
|
+
* to change the result and will not otherwise affect component rendering
|
|
47
|
+
* directly.
|
|
48
|
+
*
|
|
49
|
+
* When not defined, the hook will ensure the component re-renders to pick
|
|
50
|
+
* up the latest result.
|
|
51
|
+
*/
|
|
52
|
+
onResultChanged?: (result: Result<TData>) => void,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Scope to use with the shared cache.
|
|
56
|
+
*
|
|
57
|
+
* When specified, the given scope will be used to isolate this hook's
|
|
58
|
+
* cached results. Otherwise, a shared default scope will be used.
|
|
59
|
+
*
|
|
60
|
+
* Changing this value after the first call is not supported.
|
|
61
|
+
*/
|
|
62
|
+
scope?: string,
|
|
63
|
+
...
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Hook to execute and cache an async operation on the client.
|
|
67
|
+
*
|
|
68
|
+
* This hook executes the given handler on the client if there is no
|
|
69
|
+
* cached result to use.
|
|
70
|
+
*
|
|
71
|
+
* Results are cached so they can be shared between equivalent invocations.
|
|
72
|
+
* In-flight requests are also shared, so that concurrent calls will
|
|
73
|
+
* behave as one might exect. Cache updates invoked by one hook instance
|
|
74
|
+
* do not trigger renders in components that use the same requestID; however,
|
|
75
|
+
* that should not matter since concurrent requests will share the same
|
|
76
|
+
* in-flight request, and subsequent renders will grab from the cache.
|
|
77
|
+
*
|
|
78
|
+
* Once the request has been tried once and a non-loading response has been
|
|
79
|
+
* cached, the request will not executed made again.
|
|
80
|
+
*/
|
|
81
|
+
declare export var useCachedEffect: <TData: ValidCacheData>(
|
|
82
|
+
requestId: string,
|
|
83
|
+
handler: () => Promise<TData>,
|
|
84
|
+
options?: CachedEffectOptions<TData>
|
|
85
|
+
) => [Result<TData>, () => void];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GqlRouterConfiguration, GqlContext } from "../util/gql-types";
|
|
2
|
+
/**
|
|
3
|
+
* Construct a GqlRouterContext from the current one and partial context.
|
|
4
|
+
*/
|
|
5
|
+
export declare const useGqlRouterContext: <TContext extends GqlContext>(contextOverrides?: Partial<TContext>) => GqlRouterConfiguration<TContext>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-gql-router-context
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GqlRouterConfiguration, GqlContext } from "../util/gql-types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Construct a GqlRouterContext from the current one and partial context.
|
|
12
|
+
*/
|
|
13
|
+
declare export var useGqlRouterContext: <TContext: GqlContext>(
|
|
14
|
+
contextOverrides?: $Rest<TContext, { ... }>
|
|
15
|
+
) => GqlRouterConfiguration<TContext>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GqlContext, GqlOperation, GqlFetchOptions } from "../util/gql-types";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to obtain a gqlFetch function for performing GraphQL requests.
|
|
4
|
+
*
|
|
5
|
+
* The fetch function will resolve null if the request was aborted, otherwise
|
|
6
|
+
* it will resolve the data returned by the GraphQL server.
|
|
7
|
+
*
|
|
8
|
+
* Context is merged with the default context provided to the GqlRouter.
|
|
9
|
+
* Values in the partial context given to the returned fetch function will
|
|
10
|
+
* only be included if they have a value other than undefined.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useGql: <TContext extends GqlContext>(context?: Partial<TContext>) => <TData, TVariables extends Record<any, any>>(operation: GqlOperation<TData, TVariables>, options?: GqlFetchOptions<TVariables, TContext> | undefined) => Promise<TData>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-gql
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
GqlContext,
|
|
10
|
+
GqlOperation,
|
|
11
|
+
GqlFetchOptions,
|
|
12
|
+
} from "../util/gql-types";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Hook to obtain a gqlFetch function for performing GraphQL requests.
|
|
16
|
+
*
|
|
17
|
+
* The fetch function will resolve null if the request was aborted, otherwise
|
|
18
|
+
* it will resolve the data returned by the GraphQL server.
|
|
19
|
+
*
|
|
20
|
+
* Context is merged with the default context provided to the GqlRouter.
|
|
21
|
+
* Values in the partial context given to the returned fetch function will
|
|
22
|
+
* only be included if they have a value other than undefined.
|
|
23
|
+
*/
|
|
24
|
+
declare export var useGql: <TContext: GqlContext>(
|
|
25
|
+
context?: $Rest<TContext, { ... }>
|
|
26
|
+
) => <TData, TVariables: { [key: any]: any, ... }>(
|
|
27
|
+
operation: GqlOperation<TData, TVariables>,
|
|
28
|
+
options?: GqlFetchOptions<TVariables, TContext> | void
|
|
29
|
+
) => Promise<TData>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
2
|
+
/**
|
|
3
|
+
* Policies to define how a hydratable effect should behave client-side.
|
|
4
|
+
*/
|
|
5
|
+
export declare const WhenClientSide: {
|
|
6
|
+
/**
|
|
7
|
+
* The result from executing the effect server-side will not be hydrated.
|
|
8
|
+
* The effect will always be executed client-side.
|
|
9
|
+
*
|
|
10
|
+
* This should only be used if there is something else that is responsible
|
|
11
|
+
* for properly hydrating this component (for example, the action invokes
|
|
12
|
+
* Apollo which manages its own cache to ensure things render properly).
|
|
13
|
+
*/
|
|
14
|
+
readonly DoNotHydrate: "DoNotHydrate";
|
|
15
|
+
/**
|
|
16
|
+
* The result from executing the effect server-side will be hydrated.
|
|
17
|
+
* The effect will only execute client-side if there was no result to
|
|
18
|
+
* be hydrated (i.e. both error and success hydration results prevent the
|
|
19
|
+
* effect running client-side).
|
|
20
|
+
*/
|
|
21
|
+
readonly ExecuteWhenNoResult: "ExecuteWhenNoResult";
|
|
22
|
+
/**
|
|
23
|
+
* The result from executing the effect server-side will be hydrated.
|
|
24
|
+
* If the hydrated result is a success result, the effect will not be
|
|
25
|
+
* executed client-side.
|
|
26
|
+
* If the hydrated result was not a success result, or there was no
|
|
27
|
+
* hydrated result, the effect will not be executed.
|
|
28
|
+
*/
|
|
29
|
+
readonly ExecuteWhenNoSuccessResult: "ExecuteWhenNoSuccessResult";
|
|
30
|
+
/**
|
|
31
|
+
* The result from executing the effect server-side will be hydrated.
|
|
32
|
+
* The effect will always be executed client-side, regardless of the
|
|
33
|
+
* hydrated result status.
|
|
34
|
+
*/
|
|
35
|
+
readonly AlwaysExecute: "AlwaysExecute";
|
|
36
|
+
};
|
|
37
|
+
type HydratableEffectOptions<TData extends ValidCacheData> = {
|
|
38
|
+
/**
|
|
39
|
+
* How the hook should behave when rendering client-side for the first time.
|
|
40
|
+
*
|
|
41
|
+
* This controls how the hook hydrates and executes when client-side.
|
|
42
|
+
*
|
|
43
|
+
* Default is `WhenClientSide.ExecuteWhenNoSuccessResult`.
|
|
44
|
+
*
|
|
45
|
+
* Changing this value after the first call is irrelevant as it only
|
|
46
|
+
* affects the initial render behavior.
|
|
47
|
+
*/
|
|
48
|
+
clientBehavior?: typeof WhenClientSide[keyof typeof WhenClientSide];
|
|
49
|
+
/**
|
|
50
|
+
* When `true`, the effect will not be executed; otherwise, the effect will
|
|
51
|
+
* be executed.
|
|
52
|
+
*
|
|
53
|
+
* If this is set to `true` while the effect is still pending, the pending
|
|
54
|
+
* effect will be cancelled.
|
|
55
|
+
*
|
|
56
|
+
* Default is `false`.
|
|
57
|
+
*/
|
|
58
|
+
skip?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* When `true`, the effect will not reset the result to the loading status
|
|
61
|
+
* while executing if the requestId changes, instead, returning
|
|
62
|
+
* the existing result from before the change; otherwise, the result will
|
|
63
|
+
* be set to loading status.
|
|
64
|
+
*
|
|
65
|
+
* If the status is loading when the changes are made, it will remain as
|
|
66
|
+
* loading; old pending effects are discarded on changes and as such this
|
|
67
|
+
* value has no effect in that case.
|
|
68
|
+
*/
|
|
69
|
+
retainResultOnChange?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Callback that is invoked if the result for the given hook has changed.
|
|
72
|
+
*
|
|
73
|
+
* When defined, the hook will invoke this callback whenever it has reason
|
|
74
|
+
* to change the result and will not otherwise affect component rendering
|
|
75
|
+
* directly.
|
|
76
|
+
*
|
|
77
|
+
* When not defined, the hook will ensure the component re-renders to pick
|
|
78
|
+
* up the latest result.
|
|
79
|
+
*/
|
|
80
|
+
onResultChanged?: (result: Result<TData>) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Scope to use with the shared cache.
|
|
83
|
+
*
|
|
84
|
+
* When specified, the given scope will be used to isolate this hook's
|
|
85
|
+
* cached results. Otherwise, a shared default scope will be used.
|
|
86
|
+
*
|
|
87
|
+
* Changing this value after the first call is not supported.
|
|
88
|
+
*/
|
|
89
|
+
scope?: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Hook to execute an async operation on server and client.
|
|
93
|
+
*
|
|
94
|
+
* This hook executes the given handler on the server and on the client,
|
|
95
|
+
* and, depending on the given options, can hydrate the server-side result.
|
|
96
|
+
*
|
|
97
|
+
* Results are cached on the client so they can be shared between equivalent
|
|
98
|
+
* invocations. Cache changes from one hook instance do not trigger renders
|
|
99
|
+
* in components that use the same requestID.
|
|
100
|
+
*/
|
|
101
|
+
export declare const useHydratableEffect: <TData extends ValidCacheData>(requestId: string, handler: () => Promise<TData>, options?: HydratableEffectOptions<TData>) => Result<TData>;
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-hydratable-effect
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Policies to define how a hydratable effect should behave client-side.
|
|
12
|
+
*/
|
|
13
|
+
declare export var WhenClientSide: {
|
|
14
|
+
/**
|
|
15
|
+
* The result from executing the effect server-side will not be hydrated.
|
|
16
|
+
* The effect will always be executed client-side.
|
|
17
|
+
*
|
|
18
|
+
* This should only be used if there is something else that is responsible
|
|
19
|
+
* for properly hydrating this component (for example, the action invokes
|
|
20
|
+
* Apollo which manages its own cache to ensure things render properly).
|
|
21
|
+
*/
|
|
22
|
+
+DoNotHydrate: "DoNotHydrate",
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The result from executing the effect server-side will be hydrated.
|
|
26
|
+
* The effect will only execute client-side if there was no result to
|
|
27
|
+
* be hydrated (i.e. both error and success hydration results prevent the
|
|
28
|
+
* effect running client-side).
|
|
29
|
+
*/
|
|
30
|
+
+ExecuteWhenNoResult: "ExecuteWhenNoResult",
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The result from executing the effect server-side will be hydrated.
|
|
34
|
+
* If the hydrated result is a success result, the effect will not be
|
|
35
|
+
* executed client-side.
|
|
36
|
+
* If the hydrated result was not a success result, or there was no
|
|
37
|
+
* hydrated result, the effect will not be executed.
|
|
38
|
+
*/
|
|
39
|
+
+ExecuteWhenNoSuccessResult: "ExecuteWhenNoSuccessResult",
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The result from executing the effect server-side will be hydrated.
|
|
43
|
+
* The effect will always be executed client-side, regardless of the
|
|
44
|
+
* hydrated result status.
|
|
45
|
+
*/
|
|
46
|
+
+AlwaysExecute: "AlwaysExecute",
|
|
47
|
+
...
|
|
48
|
+
};
|
|
49
|
+
declare type HydratableEffectOptions<TData: ValidCacheData> = {
|
|
50
|
+
/**
|
|
51
|
+
* How the hook should behave when rendering client-side for the first time.
|
|
52
|
+
*
|
|
53
|
+
* This controls how the hook hydrates and executes when client-side.
|
|
54
|
+
*
|
|
55
|
+
* Default is `WhenClientSide.ExecuteWhenNoSuccessResult`.
|
|
56
|
+
*
|
|
57
|
+
* Changing this value after the first call is irrelevant as it only
|
|
58
|
+
* affects the initial render behavior.
|
|
59
|
+
*/
|
|
60
|
+
clientBehavior?: $ElementType<
|
|
61
|
+
typeof WhenClientSide,
|
|
62
|
+
$Keys<typeof WhenClientSide>
|
|
63
|
+
>,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* When `true`, the effect will not be executed; otherwise, the effect will
|
|
67
|
+
* be executed.
|
|
68
|
+
*
|
|
69
|
+
* If this is set to `true` while the effect is still pending, the pending
|
|
70
|
+
* effect will be cancelled.
|
|
71
|
+
*
|
|
72
|
+
* Default is `false`.
|
|
73
|
+
*/
|
|
74
|
+
skip?: boolean,
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* When `true`, the effect will not reset the result to the loading status
|
|
78
|
+
* while executing if the requestId changes, instead, returning
|
|
79
|
+
* the existing result from before the change; otherwise, the result will
|
|
80
|
+
* be set to loading status.
|
|
81
|
+
*
|
|
82
|
+
* If the status is loading when the changes are made, it will remain as
|
|
83
|
+
* loading; old pending effects are discarded on changes and as such this
|
|
84
|
+
* value has no effect in that case.
|
|
85
|
+
*/
|
|
86
|
+
retainResultOnChange?: boolean,
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Callback that is invoked if the result for the given hook has changed.
|
|
90
|
+
*
|
|
91
|
+
* When defined, the hook will invoke this callback whenever it has reason
|
|
92
|
+
* to change the result and will not otherwise affect component rendering
|
|
93
|
+
* directly.
|
|
94
|
+
*
|
|
95
|
+
* When not defined, the hook will ensure the component re-renders to pick
|
|
96
|
+
* up the latest result.
|
|
97
|
+
*/
|
|
98
|
+
onResultChanged?: (result: Result<TData>) => void,
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Scope to use with the shared cache.
|
|
102
|
+
*
|
|
103
|
+
* When specified, the given scope will be used to isolate this hook's
|
|
104
|
+
* cached results. Otherwise, a shared default scope will be used.
|
|
105
|
+
*
|
|
106
|
+
* Changing this value after the first call is not supported.
|
|
107
|
+
*/
|
|
108
|
+
scope?: string,
|
|
109
|
+
...
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Hook to execute an async operation on server and client.
|
|
113
|
+
*
|
|
114
|
+
* This hook executes the given handler on the server and on the client,
|
|
115
|
+
* and, depending on the given options, can hydrate the server-side result.
|
|
116
|
+
*
|
|
117
|
+
* Results are cached on the client so they can be shared between equivalent
|
|
118
|
+
* invocations. Cache changes from one hook instance do not trigger renders
|
|
119
|
+
* in components that use the same requestID.
|
|
120
|
+
*/
|
|
121
|
+
declare export var useHydratableEffect: <TData: ValidCacheData>(
|
|
122
|
+
requestId: string,
|
|
123
|
+
handler: () => Promise<TData>,
|
|
124
|
+
options?: HydratableEffectOptions<TData>
|
|
125
|
+
) => Result<TData>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ValidCacheData } from "../util/types";
|
|
2
|
+
/**
|
|
3
|
+
* Allow request handling to be intercepted.
|
|
4
|
+
*
|
|
5
|
+
* Hook to take a uniquely identified request handler and return a
|
|
6
|
+
* method that will support request interception from the InterceptRequest
|
|
7
|
+
* component.
|
|
8
|
+
*
|
|
9
|
+
* If you want request interception to be supported with `useServerEffect` or
|
|
10
|
+
* any client-side effect that uses the handler, call this first to generate
|
|
11
|
+
* an intercepted handler, and then invoke `useServerEffect` (or other things)
|
|
12
|
+
* with that intercepted handler.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useRequestInterception: <TData extends ValidCacheData>(requestId: string, handler: () => Promise<TData>) => () => Promise<TData>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-request-interception
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ValidCacheData } from "../util/types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Allow request handling to be intercepted.
|
|
12
|
+
*
|
|
13
|
+
* Hook to take a uniquely identified request handler and return a
|
|
14
|
+
* method that will support request interception from the InterceptRequest
|
|
15
|
+
* component.
|
|
16
|
+
*
|
|
17
|
+
* If you want request interception to be supported with `useServerEffect` or
|
|
18
|
+
* any client-side effect that uses the handler, call this first to generate
|
|
19
|
+
* an intercepted handler, and then invoke `useServerEffect` (or other things)
|
|
20
|
+
* with that intercepted handler.
|
|
21
|
+
*/
|
|
22
|
+
declare export var useRequestInterception: <TData: ValidCacheData>(
|
|
23
|
+
requestId: string,
|
|
24
|
+
handler: () => Promise<TData>
|
|
25
|
+
) => () => Promise<TData>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
2
|
+
type ServerEffectOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* When `true`, the result of the effect when fulfilled using Wonder Blocks
|
|
5
|
+
* Data will be stored in the hydration cache for hydrating client-side;
|
|
6
|
+
* otherwise, the result will be stored in the server-side-only cache.
|
|
7
|
+
*
|
|
8
|
+
* This should only be set to `false` if something else will be responsible
|
|
9
|
+
* for hydration of the data on the client-side (for example, if Apollo's
|
|
10
|
+
* hydration support is used).
|
|
11
|
+
*
|
|
12
|
+
* Default is `true`.
|
|
13
|
+
*/
|
|
14
|
+
hydrate?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, the effect will not be tracked for fulfillment; otherwise,
|
|
17
|
+
* the effect will be tracked for fulfillment.
|
|
18
|
+
*
|
|
19
|
+
* Default is `false`.
|
|
20
|
+
*/
|
|
21
|
+
skip?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Hook to perform an asynchronous action during server-side rendering.
|
|
25
|
+
*
|
|
26
|
+
* This hook registers an asynchronous action to be performed during
|
|
27
|
+
* server-side rendering. The action is performed only once, and the result
|
|
28
|
+
* is cached against the given identifier so that subsequent calls return that
|
|
29
|
+
* cached result allowing components to render more of the component.
|
|
30
|
+
*
|
|
31
|
+
* This hook requires the Wonder Blocks Data functionality for resolving
|
|
32
|
+
* pending requests, as well as support for the hydration cache to be
|
|
33
|
+
* embedded into a page so that the result can by hydrated (if that is a
|
|
34
|
+
* requirement).
|
|
35
|
+
*
|
|
36
|
+
* The asynchronous action is never invoked on the client-side.
|
|
37
|
+
*/
|
|
38
|
+
export declare const useServerEffect: <TData extends ValidCacheData>(requestId: string, handler: () => Promise<TData>, options?: ServerEffectOptions) => Result<TData> | null | undefined;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-server-effect
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
9
|
+
declare type ServerEffectOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* When `true`, the result of the effect when fulfilled using Wonder Blocks
|
|
12
|
+
* Data will be stored in the hydration cache for hydrating client-side;
|
|
13
|
+
* otherwise, the result will be stored in the server-side-only cache.
|
|
14
|
+
*
|
|
15
|
+
* This should only be set to `false` if something else will be responsible
|
|
16
|
+
* for hydration of the data on the client-side (for example, if Apollo's
|
|
17
|
+
* hydration support is used).
|
|
18
|
+
*
|
|
19
|
+
* Default is `true`.
|
|
20
|
+
*/
|
|
21
|
+
hydrate?: boolean,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* When `true`, the effect will not be tracked for fulfillment; otherwise,
|
|
25
|
+
* the effect will be tracked for fulfillment.
|
|
26
|
+
*
|
|
27
|
+
* Default is `false`.
|
|
28
|
+
*/
|
|
29
|
+
skip?: boolean,
|
|
30
|
+
...
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Hook to perform an asynchronous action during server-side rendering.
|
|
34
|
+
*
|
|
35
|
+
* This hook registers an asynchronous action to be performed during
|
|
36
|
+
* server-side rendering. The action is performed only once, and the result
|
|
37
|
+
* is cached against the given identifier so that subsequent calls return that
|
|
38
|
+
* cached result allowing components to render more of the component.
|
|
39
|
+
*
|
|
40
|
+
* This hook requires the Wonder Blocks Data functionality for resolving
|
|
41
|
+
* pending requests, as well as support for the hydration cache to be
|
|
42
|
+
* embedded into a page so that the result can by hydrated (if that is a
|
|
43
|
+
* requirement).
|
|
44
|
+
*
|
|
45
|
+
* The asynchronous action is never invoked on the client-side.
|
|
46
|
+
*/
|
|
47
|
+
declare export var useServerEffect: <TData: ValidCacheData>(
|
|
48
|
+
requestId: string,
|
|
49
|
+
handler: () => Promise<TData>,
|
|
50
|
+
options?: ServerEffectOptions
|
|
51
|
+
) => Result<TData> | null | void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ValidCacheData, ScopedCache } from "../util/types";
|
|
2
|
+
/**
|
|
3
|
+
* A function for inserting a value into the cache or clearing it.
|
|
4
|
+
*/
|
|
5
|
+
type CacheValueFn<TValue extends ValidCacheData> = (value?: TValue | null | undefined) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Access to the shared in-memory cache.
|
|
8
|
+
*
|
|
9
|
+
* This is the cache used by `useSharedCache` and related hooks and
|
|
10
|
+
* components.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SharedCache: ScopedCache;
|
|
13
|
+
/**
|
|
14
|
+
* Hook to retrieve data from and store data in an in-memory cache.
|
|
15
|
+
*
|
|
16
|
+
* @returns {[?ReadOnlyCacheValue, CacheValueFn]}
|
|
17
|
+
* Returns an array containing the current cache entry (or undefined), a
|
|
18
|
+
* function to set the cache entry (passing null or undefined to this function
|
|
19
|
+
* will delete the entry).
|
|
20
|
+
*
|
|
21
|
+
* NOTE: Unlike useState or useReducer, we don't automatically update folks
|
|
22
|
+
* if the value they reference changes. We might add it later (if we need to),
|
|
23
|
+
* but the likelihood here is that things won't be changing in this cache in a
|
|
24
|
+
* way where we would need that. If we do (and likely only in specific
|
|
25
|
+
* circumstances), we should consider adding a simple boolean useState that can
|
|
26
|
+
* be toggled to cause a rerender whenever the referenced cached data changes
|
|
27
|
+
* so that callers can re-render on cache changes. However, we should make
|
|
28
|
+
* sure this toggling is optional - or we could use a callback argument, to
|
|
29
|
+
* achieve this on an as-needed basis.
|
|
30
|
+
*/
|
|
31
|
+
export declare const useSharedCache: <TValue extends ValidCacheData>(id: string, scope: string, initialValue?: TValue | (() => TValue | null | undefined) | null | undefined) => [TValue | null | undefined, CacheValueFn<TValue>];
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-shared-cache
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ValidCacheData, ScopedCache } from "../util/types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A function for inserting a value into the cache or clearing it.
|
|
12
|
+
*/
|
|
13
|
+
declare type CacheValueFn<TValue: ValidCacheData> = (
|
|
14
|
+
value?: TValue | null | void
|
|
15
|
+
) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Access to the shared in-memory cache.
|
|
18
|
+
*
|
|
19
|
+
* This is the cache used by `useSharedCache` and related hooks and
|
|
20
|
+
* components.
|
|
21
|
+
*/
|
|
22
|
+
declare export var SharedCache: ScopedCache;
|
|
23
|
+
/**
|
|
24
|
+
* Hook to retrieve data from and store data in an in-memory cache.
|
|
25
|
+
* @returns {[?ReadOnlyCacheValue, CacheValueFn]} Returns an array containing the current cache entry (or undefined), a
|
|
26
|
+
* function to set the cache entry (passing null or undefined to this function
|
|
27
|
+
* will delete the entry).
|
|
28
|
+
*
|
|
29
|
+
* NOTE: Unlike useState or useReducer, we don't automatically update folks
|
|
30
|
+
* if the value they reference changes. We might add it later (if we need to),
|
|
31
|
+
* but the likelihood here is that things won't be changing in this cache in a
|
|
32
|
+
* way where we would need that. If we do (and likely only in specific
|
|
33
|
+
* circumstances), we should consider adding a simple boolean useState that can
|
|
34
|
+
* be toggled to cause a rerender whenever the referenced cached data changes
|
|
35
|
+
* so that callers can re-render on cache changes. However, we should make
|
|
36
|
+
* sure this toggling is optional - or we could use a callback argument, to
|
|
37
|
+
* achieve this on an as-needed basis.
|
|
38
|
+
*/
|
|
39
|
+
declare export var useSharedCache: <TValue: ValidCacheData>(
|
|
40
|
+
id: string,
|
|
41
|
+
scope: string,
|
|
42
|
+
initialValue?: TValue | (() => TValue | null | void) | null | void
|
|
43
|
+
) => [TValue | null | void, CacheValueFn<TValue>];
|