@isograph/react 0.0.0-main-c89c61e8 → 0.0.0-main-0eb53a17
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/.turbo/turbo-compile-libs.log +1 -1
- package/dist/core/FragmentReference.d.ts +2 -2
- package/dist/core/FragmentReference.d.ts.map +1 -1
- package/dist/core/IsographEnvironment.d.ts +7 -12
- package/dist/core/IsographEnvironment.d.ts.map +1 -1
- package/dist/core/areEqualWithDeepComparison.d.ts +3 -1
- package/dist/core/areEqualWithDeepComparison.d.ts.map +1 -1
- package/dist/core/areEqualWithDeepComparison.js +2 -0
- package/dist/core/cache.d.ts +4 -4
- package/dist/core/cache.d.ts.map +1 -1
- package/dist/core/cache.js +3 -8
- package/dist/core/check.d.ts +3 -3
- package/dist/core/check.d.ts.map +1 -1
- package/dist/core/garbageCollection.d.ts +2 -2
- package/dist/core/garbageCollection.d.ts.map +1 -1
- package/dist/core/logging.d.ts +4 -13
- package/dist/core/logging.d.ts.map +1 -1
- package/dist/core/makeNetworkRequest.d.ts.map +1 -1
- package/dist/core/read.d.ts +7 -7
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/reader.d.ts +3 -3
- package/dist/core/reader.d.ts.map +1 -1
- package/dist/core/startUpdate.d.ts.map +1 -1
- package/dist/core/startUpdate.js +0 -9
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/react/FragmentReader.d.ts +10 -4
- package/dist/react/FragmentReader.d.ts.map +1 -1
- package/dist/react/FragmentReader.js +30 -3
- package/dist/react/LoadableFieldReader.d.ts.map +1 -1
- package/dist/react/LoadableFieldReader.js +3 -0
- package/package.json +4 -4
- package/src/core/FragmentReference.ts +2 -2
- package/src/core/IsographEnvironment.ts +7 -13
- package/src/core/areEqualWithDeepComparison.ts +5 -5
- package/src/core/cache.ts +14 -22
- package/src/core/check.ts +4 -4
- package/src/core/garbageCollection.ts +3 -3
- package/src/core/logging.ts +4 -16
- package/src/core/makeNetworkRequest.ts +2 -2
- package/src/core/read.ts +10 -12
- package/src/core/reader.ts +3 -3
- package/src/core/startUpdate.ts +2 -11
- package/src/index.ts +2 -5
- package/src/react/FragmentReader.tsx +36 -17
- package/src/react/LoadableFieldReader.tsx +3 -0
- package/src/tests/__isograph/Node/asEconomist/resolver_reader.ts +1 -1
- package/src/tests/__isograph/Query/linkedUpdate/param_type.ts +4 -4
- package/src/tests/__isograph/iso.ts +1 -1
- package/dist/core/brand.d.ts +0 -2
- package/dist/core/brand.d.ts.map +0 -1
- package/dist/core/brand.js +0 -2
- package/dist/react/FragmentRenderer.d.ts +0 -15
- package/dist/react/FragmentRenderer.d.ts.map +0 -1
- package/dist/react/FragmentRenderer.js +0 -35
- package/dist/react/LoadableFieldRenderer.d.ts +0 -13
- package/dist/react/LoadableFieldRenderer.d.ts.map +0 -1
- package/dist/react/LoadableFieldRenderer.js +0 -37
- package/src/core/brand.ts +0 -18
- package/src/react/FragmentRenderer.tsx +0 -46
- package/src/react/LoadableFieldRenderer.tsx +0 -41
- package/src/tests/__isograph/Economist/link/output_type.ts +0 -2
- package/src/tests/__isograph/Node/link/output_type.ts +0 -3
- package/src/tests/__isograph/tsconfig.json +0 -8
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import {
|
|
2
3
|
type ExtractReadFromStore,
|
|
3
4
|
type IsographEntrypoint,
|
|
@@ -6,22 +7,40 @@ import { type FragmentReference } from '../core/FragmentReference';
|
|
|
6
7
|
import { type NetworkRequestReaderOptions } from '../core/read';
|
|
7
8
|
import { useResult } from './useResult';
|
|
8
9
|
|
|
10
|
+
export type IsExactlyIntrinsicAttributes<T> = T extends JSX.IntrinsicAttributes
|
|
11
|
+
? JSX.IntrinsicAttributes extends T
|
|
12
|
+
? true
|
|
13
|
+
: false
|
|
14
|
+
: false;
|
|
15
|
+
|
|
9
16
|
export function FragmentReader<
|
|
10
|
-
|
|
11
|
-
TEntrypoint extends IsographEntrypoint<any,
|
|
12
|
-
|
|
13
|
-
>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
TProps extends Record<any, any>,
|
|
18
|
+
TEntrypoint extends IsographEntrypoint<any, React.FC<TProps>, any>,
|
|
19
|
+
>(
|
|
20
|
+
props: IsExactlyIntrinsicAttributes<TProps> extends true
|
|
21
|
+
? {
|
|
22
|
+
fragmentReference: FragmentReference<
|
|
23
|
+
ExtractReadFromStore<TEntrypoint>,
|
|
24
|
+
React.FC<TProps>
|
|
25
|
+
>;
|
|
26
|
+
additionalProps?: Record<PropertyKey, never>;
|
|
27
|
+
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
28
|
+
}
|
|
29
|
+
: {
|
|
30
|
+
fragmentReference: FragmentReference<
|
|
31
|
+
ExtractReadFromStore<TEntrypoint>,
|
|
32
|
+
React.FC<TProps>
|
|
33
|
+
>;
|
|
34
|
+
additionalProps: Omit<TProps, keyof JSX.IntrinsicAttributes>;
|
|
35
|
+
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
36
|
+
},
|
|
37
|
+
): React.ReactNode {
|
|
38
|
+
const Component = useResult(
|
|
39
|
+
props.fragmentReference,
|
|
40
|
+
props.networkRequestOptions,
|
|
41
|
+
);
|
|
42
|
+
// TypeScript is not understanding that if additionalProps is Record<PropertyKey, never>,
|
|
43
|
+
// it means that TProps === JSX.IntrinsicAttributes.
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
return <Component {...props.additionalProps} />;
|
|
27
46
|
}
|
|
@@ -8,6 +8,9 @@ import { type LoadableField } from '../core/reader';
|
|
|
8
8
|
import { useClientSideDefer } from '../loadable-hooks/useClientSideDefer';
|
|
9
9
|
import { useResult } from './useResult';
|
|
10
10
|
|
|
11
|
+
// TODO
|
|
12
|
+
// - LoadableFieldRenderer, which works for @loadable fields that are components,
|
|
13
|
+
// i.e. just renders the resulting component
|
|
11
14
|
export function LoadableFieldReader<
|
|
12
15
|
TReadFromStore extends UnknownTReadFromStore,
|
|
13
16
|
TResult,
|
|
@@ -16,7 +16,7 @@ const readerAst: ReaderAst<{ data: any, parameters: Record<PropertyKey, never> }
|
|
|
16
16
|
|
|
17
17
|
const artifact: EagerReaderArtifact<
|
|
18
18
|
{ data: any, parameters: Record<PropertyKey, never> },
|
|
19
|
-
Link
|
|
19
|
+
Link | null
|
|
20
20
|
> = {
|
|
21
21
|
kind: "EagerReaderArtifact",
|
|
22
22
|
fieldName: "Node.asEconomist",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Link } from '@isograph/react';
|
|
2
2
|
import type { StartUpdate } from '@isograph/react';
|
|
3
3
|
|
|
4
4
|
export type Query__linkedUpdate__param = {
|
|
@@ -15,7 +15,7 @@ A client pointer for the Economist type.
|
|
|
15
15
|
/**
|
|
16
16
|
A store Link for the Node type.
|
|
17
17
|
*/
|
|
18
|
-
readonly link:
|
|
18
|
+
readonly link: Link,
|
|
19
19
|
/**
|
|
20
20
|
A client pointer for the Economist type.
|
|
21
21
|
*/
|
|
@@ -34,12 +34,12 @@ A client pointer for the Economist type.
|
|
|
34
34
|
name: string,
|
|
35
35
|
} | null),
|
|
36
36
|
} | null),
|
|
37
|
-
set node(value: ({ link:
|
|
37
|
+
set node(value: ({ link: Link } | null)),
|
|
38
38
|
readonly john_stuart_mill: ({
|
|
39
39
|
/**
|
|
40
40
|
A store Link for the Node type.
|
|
41
41
|
*/
|
|
42
|
-
readonly link:
|
|
42
|
+
readonly link: Link,
|
|
43
43
|
/**
|
|
44
44
|
A client pointer for the Economist type.
|
|
45
45
|
*/
|
|
@@ -16,7 +16,7 @@ import entrypoint_Query__subquery from '../__isograph/Query/subquery/entrypoint'
|
|
|
16
16
|
// This means that the type of the exported iso literal is exactly
|
|
17
17
|
// the type of the passed-in function, which takes one parameter
|
|
18
18
|
// of type TParam.
|
|
19
|
-
type IdentityWithParam<TParam extends object
|
|
19
|
+
type IdentityWithParam<TParam extends object> = <TClientFieldReturn>(
|
|
20
20
|
clientField: (param: TParam) => TClientFieldReturn
|
|
21
21
|
) => (param: TParam) => TClientFieldReturn;
|
|
22
22
|
|
package/dist/core/brand.d.ts
DELETED
package/dist/core/brand.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/core/brand.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,KAAK,CACf,QAAQ,EACR,KAAK,SAAS,MAAM,GAAG,MAAM,IAE3B,MAAM,CAAC,SAAS,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC"}
|
package/dist/core/brand.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { type ExtractReadFromStore, type IsographEntrypoint } from '../core/entrypoint';
|
|
3
|
-
import { type FragmentReference } from '../core/FragmentReference';
|
|
4
|
-
import { type NetworkRequestReaderOptions } from '../core/read';
|
|
5
|
-
export type IsExactlyIntrinsicAttributes<T> = T extends JSX.IntrinsicAttributes ? JSX.IntrinsicAttributes extends T ? true : false : false;
|
|
6
|
-
export declare function FragmentRenderer<TProps extends Record<any, any>, TEntrypoint extends IsographEntrypoint<any, React.FC<TProps>, any>>(props: IsExactlyIntrinsicAttributes<TProps> extends true ? {
|
|
7
|
-
fragmentReference: FragmentReference<ExtractReadFromStore<TEntrypoint>, React.FC<TProps>>;
|
|
8
|
-
additionalProps?: Record<PropertyKey, never>;
|
|
9
|
-
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
10
|
-
} : {
|
|
11
|
-
fragmentReference: FragmentReference<ExtractReadFromStore<TEntrypoint>, React.FC<TProps>>;
|
|
12
|
-
additionalProps: Omit<TProps, keyof JSX.IntrinsicAttributes>;
|
|
13
|
-
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
14
|
-
}): React.ReactNode;
|
|
15
|
-
//# sourceMappingURL=FragmentRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FragmentRenderer.d.ts","sourceRoot":"","sources":["../../src/react/FragmentRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAGhE,MAAM,MAAM,4BAA4B,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,mBAAmB,GAC3E,GAAG,CAAC,mBAAmB,SAAS,CAAC,GAC/B,IAAI,GACJ,KAAK,GACP,KAAK,CAAC;AAEV,wBAAgB,gBAAgB,CAC9B,MAAM,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAC/B,WAAW,SAAS,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,EAElE,KAAK,EAAE,4BAA4B,CAAC,MAAM,CAAC,SAAS,IAAI,GACpD;IACE,iBAAiB,EAAE,iBAAiB,CAClC,oBAAoB,CAAC,WAAW,CAAC,EACjC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CACjB,CAAC;IACF,eAAe,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC7C,qBAAqB,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAC9D,GACD;IACE,iBAAiB,EAAE,iBAAiB,CAClC,oBAAoB,CAAC,WAAW,CAAC,EACjC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CACjB,CAAC;IACF,eAAe,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC7D,qBAAqB,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAC9D,GACJ,KAAK,CAAC,SAAS,CASjB"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.FragmentRenderer = FragmentRenderer;
|
|
27
|
-
const React = __importStar(require("react"));
|
|
28
|
-
const useResult_1 = require("./useResult");
|
|
29
|
-
function FragmentRenderer(props) {
|
|
30
|
-
const Component = (0, useResult_1.useResult)(props.fragmentReference, props.networkRequestOptions);
|
|
31
|
-
// TypeScript is not understanding that if additionalProps is Record<PropertyKey, never>,
|
|
32
|
-
// it means that TProps === JSX.IntrinsicAttributes.
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
return React.createElement(Component, Object.assign({}, props.additionalProps));
|
|
35
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { type FetchOptions } from '../core/check';
|
|
3
|
-
import { ExtractParameters, type UnknownTReadFromStore } from '../core/FragmentReference';
|
|
4
|
-
import { type NetworkRequestReaderOptions } from '../core/read';
|
|
5
|
-
import { type LoadableField } from '../core/reader';
|
|
6
|
-
export declare function LoadableFieldRenderer<TReadFromStore extends UnknownTReadFromStore, TProvidedArgs extends object, TChildrenResult, TProps>(props: {
|
|
7
|
-
loadableField: LoadableField<TReadFromStore, React.FC<TProps>, Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs>>;
|
|
8
|
-
args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs>;
|
|
9
|
-
fetchOptions?: FetchOptions<React.FC<TProps>>;
|
|
10
|
-
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
11
|
-
additionalProps: Omit<TProps, keyof JSX.IntrinsicAttributes>;
|
|
12
|
-
}): TChildrenResult;
|
|
13
|
-
//# sourceMappingURL=LoadableFieldRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LoadableFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/react/LoadableFieldRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,iBAAiB,EACjB,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,wBAAgB,qBAAqB,CACnC,cAAc,SAAS,qBAAqB,EAC5C,aAAa,SAAS,MAAM,EAC5B,eAAe,EACf,MAAM,EACN,KAAK,EAAE;IACP,aAAa,EAAE,aAAa,CAC1B,cAAc,EACd,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,EAChB,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,MAAM,aAAa,CAAC,CAC7D,CAAC;IAEF,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,MAAM,aAAa,CAAC,CAAC;IACnE,YAAY,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,qBAAqB,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAC7D,eAAe,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,mBAAmB,CAAC,CAAC;CAC9D,GAAG,eAAe,CAalB"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.LoadableFieldRenderer = LoadableFieldRenderer;
|
|
27
|
-
const React = __importStar(require("react"));
|
|
28
|
-
const useClientSideDefer_1 = require("../loadable-hooks/useClientSideDefer");
|
|
29
|
-
const useResult_1 = require("./useResult");
|
|
30
|
-
function LoadableFieldRenderer(props) {
|
|
31
|
-
const { fragmentReference } = (0, useClientSideDefer_1.useClientSideDefer)(props.loadableField, props.args, props.fetchOptions);
|
|
32
|
-
const Component = (0, useResult_1.useResult)(fragmentReference, props.networkRequestOptions);
|
|
33
|
-
// TODO we probably can figure out a way to convince TypeScript of
|
|
34
|
-
// the validity of this.
|
|
35
|
-
// @ts-expect-error
|
|
36
|
-
return React.createElement(Component, Object.assign({}, props.additionalProps));
|
|
37
|
-
}
|
package/src/core/brand.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Suppress the TypeScript compiler warning for this branded-type trick.
|
|
2
|
-
// See discussion: https://github.com/microsoft/TypeScript/issues/202#issuecomment-436900738
|
|
3
|
-
// Pattern: “Brand<BaseType, Brand>” leverages TypeScript conditional and `infer` types to create a pseudo-nominal type,
|
|
4
|
-
// enabling BaseType to be treated as distinct only when tagged with Brand, even though Brand doesn't exist at runtime.
|
|
5
|
-
//
|
|
6
|
-
// Explanation:
|
|
7
|
-
// - Brand extends `symbol | string` acts as a “brand” identifier.
|
|
8
|
-
// - The type uses a conditional check `infer _ extends Brand ? BaseType : never` to strip out BaseType when the branding doesn't match.
|
|
9
|
-
// - This yields a branded type system: `Brand<string, "UserId">` is not accidentally assignable to `Brand<string, "ProductId">`.
|
|
10
|
-
//
|
|
11
|
-
// Usage: Helps enforce semantic distinctions (e.g., distinguishing user IDs from product IDs) even when their runtime values are both strings.
|
|
12
|
-
//
|
|
13
|
-
// Caveat: This is purely a compile-time trick—Brand is erased in emitted JavaScript, so runtime checks must rely on other mechanisms.
|
|
14
|
-
export type Brand<
|
|
15
|
-
BaseType,
|
|
16
|
-
Brand extends symbol | string,
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
> = infer _ extends Brand ? BaseType : never;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type ExtractReadFromStore,
|
|
4
|
-
type IsographEntrypoint,
|
|
5
|
-
} from '../core/entrypoint';
|
|
6
|
-
import { type FragmentReference } from '../core/FragmentReference';
|
|
7
|
-
import { type NetworkRequestReaderOptions } from '../core/read';
|
|
8
|
-
import { useResult } from './useResult';
|
|
9
|
-
|
|
10
|
-
export type IsExactlyIntrinsicAttributes<T> = T extends JSX.IntrinsicAttributes
|
|
11
|
-
? JSX.IntrinsicAttributes extends T
|
|
12
|
-
? true
|
|
13
|
-
: false
|
|
14
|
-
: false;
|
|
15
|
-
|
|
16
|
-
export function FragmentRenderer<
|
|
17
|
-
TProps extends Record<any, any>,
|
|
18
|
-
TEntrypoint extends IsographEntrypoint<any, React.FC<TProps>, any>,
|
|
19
|
-
>(
|
|
20
|
-
props: IsExactlyIntrinsicAttributes<TProps> extends true
|
|
21
|
-
? {
|
|
22
|
-
fragmentReference: FragmentReference<
|
|
23
|
-
ExtractReadFromStore<TEntrypoint>,
|
|
24
|
-
React.FC<TProps>
|
|
25
|
-
>;
|
|
26
|
-
additionalProps?: Record<PropertyKey, never>;
|
|
27
|
-
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
28
|
-
}
|
|
29
|
-
: {
|
|
30
|
-
fragmentReference: FragmentReference<
|
|
31
|
-
ExtractReadFromStore<TEntrypoint>,
|
|
32
|
-
React.FC<TProps>
|
|
33
|
-
>;
|
|
34
|
-
additionalProps: Omit<TProps, keyof JSX.IntrinsicAttributes>;
|
|
35
|
-
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
36
|
-
},
|
|
37
|
-
): React.ReactNode {
|
|
38
|
-
const Component = useResult(
|
|
39
|
-
props.fragmentReference,
|
|
40
|
-
props.networkRequestOptions,
|
|
41
|
-
);
|
|
42
|
-
// TypeScript is not understanding that if additionalProps is Record<PropertyKey, never>,
|
|
43
|
-
// it means that TProps === JSX.IntrinsicAttributes.
|
|
44
|
-
// @ts-expect-error
|
|
45
|
-
return <Component {...props.additionalProps} />;
|
|
46
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { type FetchOptions } from '../core/check';
|
|
3
|
-
import {
|
|
4
|
-
ExtractParameters,
|
|
5
|
-
type UnknownTReadFromStore,
|
|
6
|
-
} from '../core/FragmentReference';
|
|
7
|
-
import { type NetworkRequestReaderOptions } from '../core/read';
|
|
8
|
-
import { type LoadableField } from '../core/reader';
|
|
9
|
-
import { useClientSideDefer } from '../loadable-hooks/useClientSideDefer';
|
|
10
|
-
import { useResult } from './useResult';
|
|
11
|
-
|
|
12
|
-
export function LoadableFieldRenderer<
|
|
13
|
-
TReadFromStore extends UnknownTReadFromStore,
|
|
14
|
-
TProvidedArgs extends object,
|
|
15
|
-
TChildrenResult,
|
|
16
|
-
TProps,
|
|
17
|
-
>(props: {
|
|
18
|
-
loadableField: LoadableField<
|
|
19
|
-
TReadFromStore,
|
|
20
|
-
React.FC<TProps>,
|
|
21
|
-
Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs>
|
|
22
|
-
>;
|
|
23
|
-
// TODO we can improve this to not require args if its an empty object
|
|
24
|
-
args: Omit<ExtractParameters<TReadFromStore>, keyof TProvidedArgs>;
|
|
25
|
-
fetchOptions?: FetchOptions<React.FC<TProps>>;
|
|
26
|
-
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
|
27
|
-
additionalProps: Omit<TProps, keyof JSX.IntrinsicAttributes>;
|
|
28
|
-
}): TChildrenResult {
|
|
29
|
-
const { fragmentReference } = useClientSideDefer(
|
|
30
|
-
props.loadableField,
|
|
31
|
-
props.args,
|
|
32
|
-
props.fetchOptions,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const Component = useResult(fragmentReference, props.networkRequestOptions);
|
|
36
|
-
|
|
37
|
-
// TODO we probably can figure out a way to convince TypeScript of
|
|
38
|
-
// the validity of this.
|
|
39
|
-
// @ts-expect-error
|
|
40
|
-
return <Component {...props.additionalProps} />;
|
|
41
|
-
}
|