@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-data
|
|
2
2
|
|
|
3
|
+
## 10.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [779b031d]
|
|
8
|
+
- @khanacademy/wonder-blocks-core@4.9.0
|
|
9
|
+
|
|
10
|
+
## 10.1.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- d816af08: Update build and test configs use TypeScript
|
|
15
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
16
|
+
- 3813715d: Update wonder-stuff dependencies (non-functional changes)
|
|
17
|
+
- 0d28bb1c: Configured TypeScript
|
|
18
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
19
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
20
|
+
- 2983c05b: Include 'types' field in package.json
|
|
21
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
22
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
23
|
+
- Updated dependencies [d816af08]
|
|
24
|
+
- Updated dependencies [3891f544]
|
|
25
|
+
- Updated dependencies [0d28bb1c]
|
|
26
|
+
- Updated dependencies [873f4a14]
|
|
27
|
+
- Updated dependencies [3d05f764]
|
|
28
|
+
- Updated dependencies [c2ec4902]
|
|
29
|
+
- Updated dependencies [2983c05b]
|
|
30
|
+
- Updated dependencies [77ff6a66]
|
|
31
|
+
- Updated dependencies [ec8d4b7f]
|
|
32
|
+
- @khanacademy/wonder-blocks-core@4.8.0
|
|
33
|
+
|
|
3
34
|
## 10.1.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { WhenClientSide } from "../hooks/use-hydratable-effect";
|
|
3
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
4
|
+
type Props<
|
|
5
|
+
/**
|
|
6
|
+
* The type of data resolved by the handler's fulfillRequest method.
|
|
7
|
+
*/
|
|
8
|
+
TData extends ValidCacheData> = {
|
|
9
|
+
/**
|
|
10
|
+
* A unique identifier for the request.
|
|
11
|
+
*
|
|
12
|
+
* This should not be shared by other uses of this component.
|
|
13
|
+
*/
|
|
14
|
+
requestId: string;
|
|
15
|
+
/**
|
|
16
|
+
* This defines how the request is fulfilled.
|
|
17
|
+
*
|
|
18
|
+
* If this is changed without changing the ID, there are cases where the
|
|
19
|
+
* old handler result may be given. This is not a supported mode of
|
|
20
|
+
* operation.
|
|
21
|
+
*/
|
|
22
|
+
handler: () => Promise<TData>;
|
|
23
|
+
/**
|
|
24
|
+
* How the hook should behave when rendering client-side for the first time.
|
|
25
|
+
*
|
|
26
|
+
* This controls how the hook hydrates and executes when client-side.
|
|
27
|
+
*
|
|
28
|
+
* Default is `OnClientRender.ExecuteWhenNoSuccessResult`.
|
|
29
|
+
*/
|
|
30
|
+
clientBehavior?: typeof WhenClientSide[keyof typeof WhenClientSide];
|
|
31
|
+
/**
|
|
32
|
+
* When true, the children will be rendered with the existing result
|
|
33
|
+
* until the pending load is completed. Otherwise, the children will be
|
|
34
|
+
* given a loading state until the request is fulfilled.
|
|
35
|
+
*
|
|
36
|
+
* Defaults to false.
|
|
37
|
+
*/
|
|
38
|
+
retainResultOnChange?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* A function that will render the content of this component using the
|
|
41
|
+
* loading state and data or error that gets retrieved from cache or loaded
|
|
42
|
+
* via the request if no cached value is available.
|
|
43
|
+
*/
|
|
44
|
+
children: (result: Result<TData>) => React.ReactElement;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* This component is the main component of Wonder Blocks Data. With this, data
|
|
48
|
+
* requirements can be placed in a React application in a manner that will
|
|
49
|
+
* support server-side rendering and efficient caching.
|
|
50
|
+
*/
|
|
51
|
+
declare const Data: React.FC<Props<any>>;
|
|
52
|
+
export default Data;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for data
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { WhenClientSide } from "../hooks/use-hydratable-effect";
|
|
10
|
+
import type { Result, ValidCacheData } from "../util/types";
|
|
11
|
+
declare type Props<TData: ValidCacheData> = {
|
|
12
|
+
/**
|
|
13
|
+
* A unique identifier for the request.
|
|
14
|
+
*
|
|
15
|
+
* This should not be shared by other uses of this component.
|
|
16
|
+
*/
|
|
17
|
+
requestId: string,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This defines how the request is fulfilled.
|
|
21
|
+
*
|
|
22
|
+
* If this is changed without changing the ID, there are cases where the
|
|
23
|
+
* old handler result may be given. This is not a supported mode of
|
|
24
|
+
* operation.
|
|
25
|
+
*/
|
|
26
|
+
handler: () => Promise<TData>,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* How the hook should behave when rendering client-side for the first time.
|
|
30
|
+
*
|
|
31
|
+
* This controls how the hook hydrates and executes when client-side.
|
|
32
|
+
*
|
|
33
|
+
* Default is `OnClientRender.ExecuteWhenNoSuccessResult`.
|
|
34
|
+
*/
|
|
35
|
+
clientBehavior?: $ElementType<
|
|
36
|
+
typeof WhenClientSide,
|
|
37
|
+
$Keys<typeof WhenClientSide>
|
|
38
|
+
>,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* When true, the children will be rendered with the existing result
|
|
42
|
+
* until the pending load is completed. Otherwise, the children will be
|
|
43
|
+
* given a loading state until the request is fulfilled.
|
|
44
|
+
*
|
|
45
|
+
* Defaults to false.
|
|
46
|
+
*/
|
|
47
|
+
retainResultOnChange?: boolean,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A function that will render the content of this component using the
|
|
51
|
+
* loading state and data or error that gets retrieved from cache or loaded
|
|
52
|
+
* via the request if no cached value is available.
|
|
53
|
+
*/
|
|
54
|
+
children: (result: Result<TData>) => React.Element<>,
|
|
55
|
+
...
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* This component is the main component of Wonder Blocks Data. With this, data
|
|
59
|
+
* requirements can be placed in a React application in a manner that will
|
|
60
|
+
* support server-side rendering and efficient caching.
|
|
61
|
+
*/
|
|
62
|
+
declare var Data: React.FC<Props<any>>;
|
|
63
|
+
declare export default typeof Data;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { GqlContext, GqlFetchFn } from "../util/gql-types";
|
|
3
|
+
type Props<TContext extends GqlContext> = {
|
|
4
|
+
/**
|
|
5
|
+
* The default context to be used by operations when no context is provided.
|
|
6
|
+
*/
|
|
7
|
+
defaultContext: TContext;
|
|
8
|
+
/**
|
|
9
|
+
* The function to use when fetching requests.
|
|
10
|
+
*/
|
|
11
|
+
fetch: GqlFetchFn<any, any, TContext>;
|
|
12
|
+
/**
|
|
13
|
+
* The children to be rendered inside the router.
|
|
14
|
+
*/
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Configure GraphQL routing for GraphQL hooks and components.
|
|
19
|
+
*
|
|
20
|
+
* These can be nested. Components and hooks relying on the GraphQL routing
|
|
21
|
+
* will use the configuration from their closest ancestral GqlRouter.
|
|
22
|
+
*/
|
|
23
|
+
export declare const GqlRouter: React.FC<Props<any>>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for gql-router
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { GqlContext, GqlFetchFn } from "../util/gql-types";
|
|
10
|
+
declare type Props<TContext: GqlContext> = {
|
|
11
|
+
/**
|
|
12
|
+
* The default context to be used by operations when no context is provided.
|
|
13
|
+
*/
|
|
14
|
+
defaultContext: TContext,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The function to use when fetching requests.
|
|
18
|
+
*/
|
|
19
|
+
fetch: GqlFetchFn<any, any, TContext>,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The children to be rendered inside the router.
|
|
23
|
+
*/
|
|
24
|
+
children: React.Node,
|
|
25
|
+
...
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Configure GraphQL routing for GraphQL hooks and components.
|
|
29
|
+
*
|
|
30
|
+
* These can be nested. Components and hooks relying on the GraphQL routing
|
|
31
|
+
* will use the configuration from their closest ancestral GqlRouter.
|
|
32
|
+
*/
|
|
33
|
+
declare export var GqlRouter: React.FC<Props<any>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ValidCacheData } from "../util/types";
|
|
3
|
+
type InterceptContextData = ReadonlyArray<(requestId: string) => Promise<ValidCacheData | null | undefined> | null | undefined>;
|
|
4
|
+
/**
|
|
5
|
+
* InterceptContext defines a map from request ID to interception methods.
|
|
6
|
+
*
|
|
7
|
+
* INTERNAL USE ONLY
|
|
8
|
+
*/
|
|
9
|
+
declare const InterceptContext: React.Context<InterceptContextData>;
|
|
10
|
+
export default InterceptContext;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for intercept-context
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { ValidCacheData } from "../util/types";
|
|
10
|
+
declare type InterceptContextData = $ReadOnlyArray<
|
|
11
|
+
(requestId: string) => Promise<ValidCacheData | null | void> | null | void
|
|
12
|
+
>;
|
|
13
|
+
/**
|
|
14
|
+
* InterceptContext defines a map from request ID to interception methods.
|
|
15
|
+
*
|
|
16
|
+
* INTERNAL USE ONLY
|
|
17
|
+
*/
|
|
18
|
+
declare var InterceptContext: React.Context<InterceptContextData>;
|
|
19
|
+
declare export default typeof InterceptContext;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ValidCacheData } from "../util/types";
|
|
3
|
+
type Props<TData extends ValidCacheData> = {
|
|
4
|
+
/**
|
|
5
|
+
* Called to intercept and possibly handle the request.
|
|
6
|
+
* If this returns null, the request will be handled by ancestor
|
|
7
|
+
* any ancestor interceptors, and ultimately, the original request
|
|
8
|
+
* handler, otherwise, this interceptor is handling the request.
|
|
9
|
+
*
|
|
10
|
+
* Interceptors are called in ancestor precedence, with the closest
|
|
11
|
+
* interceptor ancestor being called first, and the furthest ancestor
|
|
12
|
+
* being called last.
|
|
13
|
+
*
|
|
14
|
+
* Beware: Interceptors do not care about what data they are intercepting,
|
|
15
|
+
* so make sure to only intercept requests that you recognize from the
|
|
16
|
+
* identifier.
|
|
17
|
+
*/
|
|
18
|
+
interceptor: (requestId: string) => Promise<TData> | null | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The children to render within this component. Any requests by `Data`
|
|
21
|
+
* components that use same ID as this component will be intercepted.
|
|
22
|
+
* If `InterceptRequests` is used within `children`, that interception will
|
|
23
|
+
* be given a chance to intercept first.
|
|
24
|
+
*/
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* This component provides a mechanism to intercept data requests.
|
|
29
|
+
* This is for use in testing.
|
|
30
|
+
*
|
|
31
|
+
* This component is not recommended for use in production code as it
|
|
32
|
+
* can prevent predictable functioning of the Wonder Blocks Data framework.
|
|
33
|
+
* One possible side-effect is that inflight requests from the interceptor could
|
|
34
|
+
* be picked up by `Data` component requests from outside the children of this
|
|
35
|
+
* component.
|
|
36
|
+
*
|
|
37
|
+
* Interceptions within the same component tree are chained such that the
|
|
38
|
+
* interceptor closest to the intercepted request is called first, and the
|
|
39
|
+
* furthest interceptor is called last.
|
|
40
|
+
*/
|
|
41
|
+
declare const InterceptRequests: React.FC<Props<any>>;
|
|
42
|
+
export default InterceptRequests;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for intercept-requests
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { ValidCacheData } from "../util/types";
|
|
10
|
+
declare type Props<TData: ValidCacheData> = {
|
|
11
|
+
/**
|
|
12
|
+
* Called to intercept and possibly handle the request.
|
|
13
|
+
* If this returns null, the request will be handled by ancestor
|
|
14
|
+
* any ancestor interceptors, and ultimately, the original request
|
|
15
|
+
* handler, otherwise, this interceptor is handling the request.
|
|
16
|
+
*
|
|
17
|
+
* Interceptors are called in ancestor precedence, with the closest
|
|
18
|
+
* interceptor ancestor being called first, and the furthest ancestor
|
|
19
|
+
* being called last.
|
|
20
|
+
*
|
|
21
|
+
* Beware: Interceptors do not care about what data they are intercepting,
|
|
22
|
+
* so make sure to only intercept requests that you recognize from the
|
|
23
|
+
* identifier.
|
|
24
|
+
*/
|
|
25
|
+
interceptor: (requestId: string) => Promise<TData> | null | void,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The children to render within this component. Any requests by `Data`
|
|
29
|
+
* components that use same ID as this component will be intercepted.
|
|
30
|
+
* If `InterceptRequests` is used within `children`, that interception will
|
|
31
|
+
* be given a chance to intercept first.
|
|
32
|
+
*/
|
|
33
|
+
children: React.Node,
|
|
34
|
+
...
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* This component provides a mechanism to intercept data requests.
|
|
38
|
+
* This is for use in testing.
|
|
39
|
+
*
|
|
40
|
+
* This component is not recommended for use in production code as it
|
|
41
|
+
* can prevent predictable functioning of the Wonder Blocks Data framework.
|
|
42
|
+
* One possible side-effect is that inflight requests from the interceptor could
|
|
43
|
+
* be picked up by `Data` component requests from outside the children of this
|
|
44
|
+
* component.
|
|
45
|
+
*
|
|
46
|
+
* Interceptions within the same component tree are chained such that the
|
|
47
|
+
* interceptor closest to the intercepted request is called first, and the
|
|
48
|
+
* furthest interceptor is called last.
|
|
49
|
+
*/
|
|
50
|
+
declare var InterceptRequests: React.FC<Props<any>>;
|
|
51
|
+
declare export default typeof InterceptRequests;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type TrackDataProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Component to enable data request tracking when server-side rendering.
|
|
7
|
+
*/
|
|
8
|
+
export default class TrackData extends React.Component<TrackDataProps> {
|
|
9
|
+
render(): React.ReactElement;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for track-data
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
declare type TrackDataProps = {
|
|
10
|
+
children: React.Node,
|
|
11
|
+
...
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Component to enable data request tracking when server-side rendering.
|
|
15
|
+
*/
|
|
16
|
+
declare export default class TrackData extends React.Component<TrackDataProps> {
|
|
17
|
+
render(): React.Element<>;
|
|
18
|
+
}
|