@isograph/react 0.0.0-main-6c4d9bd8 → 0.0.0-main-edade9ce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/cache.js +4 -1
- package/dist/core/read.d.ts +3 -2
- package/dist/core/read.js +9 -1
- package/dist/react/FragmentReader.d.ts +2 -2
- package/dist/react/FragmentReader.js +1 -2
- package/dist/react/useResult.d.ts +1 -1
- package/dist/react/useResult.js +3 -1
- package/package.json +4 -4
- package/src/core/cache.ts +4 -1
- package/src/core/read.ts +11 -2
- package/src/react/FragmentReader.tsx +3 -3
- package/src/react/useResult.ts +8 -2
package/dist/core/cache.js
CHANGED
@@ -132,7 +132,10 @@ function callSubscriptions(environment, recordsEncounteredWhenNormalizing) {
|
|
132
132
|
// - consistency
|
133
133
|
// - it's also weird, this is called from makeNetworkRequest, where
|
134
134
|
// we don't currently pass network request options
|
135
|
-
{
|
135
|
+
{
|
136
|
+
suspendIfInFlight: false,
|
137
|
+
throwOnNetworkError: false,
|
138
|
+
});
|
136
139
|
if (!(0, areEqualWithDeepComparison_1.areEqualObjectsWithDeepComparison)(subscription.encounteredDataAndRecords.item, newEncounteredDataAndRecords.item)) {
|
137
140
|
if (typeof window !== 'undefined' && window.__LOG) {
|
138
141
|
console.log('Deep equality - No', {
|
package/dist/core/read.d.ts
CHANGED
@@ -6,6 +6,7 @@ export type WithEncounteredRecords<T> = {
|
|
6
6
|
};
|
7
7
|
export declare function readButDoNotEvaluate<TReadFromStore extends Object>(environment: IsographEnvironment, fragmentReference: FragmentReference<TReadFromStore, unknown>, networkRequestOptions: NetworkRequestReaderOptions): WithEncounteredRecords<TReadFromStore>;
|
8
8
|
export type NetworkRequestReaderOptions = {
|
9
|
-
suspendIfInFlight
|
10
|
-
throwOnNetworkError
|
9
|
+
suspendIfInFlight: boolean;
|
10
|
+
throwOnNetworkError: boolean;
|
11
11
|
};
|
12
|
+
export declare function getNetworkRequestOptionsWithDefaults(networkRequestOptions?: Partial<NetworkRequestReaderOptions> | void): NetworkRequestReaderOptions;
|
package/dist/core/read.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.readButDoNotEvaluate = void 0;
|
3
|
+
exports.getNetworkRequestOptionsWithDefaults = exports.readButDoNotEvaluate = void 0;
|
4
4
|
const cache_1 = require("./cache");
|
5
5
|
const componentCache_1 = require("./componentCache");
|
6
6
|
const IsographEnvironment_1 = require("./IsographEnvironment");
|
@@ -329,6 +329,14 @@ function writeQueryArgsToVariables(targetVariables, queryArgs, variables) {
|
|
329
329
|
}
|
330
330
|
}
|
331
331
|
}
|
332
|
+
function getNetworkRequestOptionsWithDefaults(networkRequestOptions) {
|
333
|
+
var _a, _b;
|
334
|
+
return {
|
335
|
+
suspendIfInFlight: (_a = networkRequestOptions === null || networkRequestOptions === void 0 ? void 0 : networkRequestOptions.suspendIfInFlight) !== null && _a !== void 0 ? _a : false,
|
336
|
+
throwOnNetworkError: (_b = networkRequestOptions === null || networkRequestOptions === void 0 ? void 0 : networkRequestOptions.throwOnNetworkError) !== null && _b !== void 0 ? _b : true,
|
337
|
+
};
|
338
|
+
}
|
339
|
+
exports.getNetworkRequestOptionsWithDefaults = getNetworkRequestOptionsWithDefaults;
|
332
340
|
// TODO use a description of the params for this?
|
333
341
|
// TODO call stableStringifyArgs on the variable values, as well.
|
334
342
|
// This doesn't matter for now, since we are just using primitive values
|
@@ -5,9 +5,9 @@ import { NetworkRequestReaderOptions } from '../core/read';
|
|
5
5
|
export declare function FragmentReader<TProps extends Record<any, any>, TEntrypoint extends IsographEntrypoint<any, React.FC<TProps>>>(props: TProps extends Record<string, never> ? {
|
6
6
|
fragmentReference: FragmentReference<ExtractReadFromStore<TEntrypoint>, React.FC<{}>>;
|
7
7
|
additionalProps?: TProps;
|
8
|
-
networkRequestOptions?: NetworkRequestReaderOptions
|
8
|
+
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
9
9
|
} : {
|
10
10
|
fragmentReference: FragmentReference<ExtractReadFromStore<TEntrypoint>, React.FC<TProps>>;
|
11
11
|
additionalProps: TProps;
|
12
|
-
networkRequestOptions?: NetworkRequestReaderOptions
|
12
|
+
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
13
13
|
}): React.ReactNode;
|
@@ -27,8 +27,7 @@ exports.FragmentReader = void 0;
|
|
27
27
|
const React = __importStar(require("react"));
|
28
28
|
const useResult_1 = require("./useResult");
|
29
29
|
function FragmentReader(props) {
|
30
|
-
|
31
|
-
const Component = (0, useResult_1.useResult)(props.fragmentReference, (_a = props.networkRequestOptions) !== null && _a !== void 0 ? _a : {});
|
30
|
+
const Component = (0, useResult_1.useResult)(props.fragmentReference, props.networkRequestOptions);
|
32
31
|
return React.createElement(Component, Object.assign({}, props.additionalProps));
|
33
32
|
}
|
34
33
|
exports.FragmentReader = FragmentReader;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FragmentReference } from '../core/FragmentReference';
|
2
2
|
import { NetworkRequestReaderOptions } from '../core/read';
|
3
3
|
import { PromiseWrapper } from '../core/PromiseWrapper';
|
4
|
-
export declare function useResult<TReadFromStore extends Object, TClientFieldValue>(fragmentReference: FragmentReference<TReadFromStore, TClientFieldValue>,
|
4
|
+
export declare function useResult<TReadFromStore extends Object, TClientFieldValue>(fragmentReference: FragmentReference<TReadFromStore, TClientFieldValue>, partialNetworkRequestOptions?: Partial<NetworkRequestReaderOptions> | void): TClientFieldValue;
|
5
5
|
export declare function maybeUnwrapNetworkRequest(networkRequest: PromiseWrapper<void, any>, networkRequestOptions: NetworkRequestReaderOptions): void;
|
package/dist/react/useResult.js
CHANGED
@@ -4,9 +4,11 @@ exports.maybeUnwrapNetworkRequest = exports.useResult = void 0;
|
|
4
4
|
const IsographEnvironmentProvider_1 = require("../react/IsographEnvironmentProvider");
|
5
5
|
const componentCache_1 = require("../core/componentCache");
|
6
6
|
const useReadAndSubscribe_1 = require("./useReadAndSubscribe");
|
7
|
+
const read_1 = require("../core/read");
|
7
8
|
const PromiseWrapper_1 = require("../core/PromiseWrapper");
|
8
|
-
function useResult(fragmentReference,
|
9
|
+
function useResult(fragmentReference, partialNetworkRequestOptions) {
|
9
10
|
const environment = (0, IsographEnvironmentProvider_1.useIsographEnvironment)();
|
11
|
+
const networkRequestOptions = (0, read_1.getNetworkRequestOptionsWithDefaults)(partialNetworkRequestOptions);
|
10
12
|
maybeUnwrapNetworkRequest(fragmentReference.networkRequest, networkRequestOptions);
|
11
13
|
switch (fragmentReference.readerArtifact.kind) {
|
12
14
|
case 'ComponentReaderArtifact': {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@isograph/react",
|
3
|
-
"version": "0.0.0-main-
|
3
|
+
"version": "0.0.0-main-edade9ce",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"homepage": "https://isograph.dev",
|
6
6
|
"main": "dist/index.js",
|
@@ -17,9 +17,9 @@
|
|
17
17
|
"tsc": "tsc"
|
18
18
|
},
|
19
19
|
"dependencies": {
|
20
|
-
"@isograph/disposable-types": "0.0.0-main-
|
21
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
22
|
-
"@isograph/reference-counted-pointer": "0.0.0-main-
|
20
|
+
"@isograph/disposable-types": "0.0.0-main-edade9ce",
|
21
|
+
"@isograph/react-disposable-state": "0.0.0-main-edade9ce",
|
22
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-edade9ce",
|
23
23
|
"react": "^18.2.0"
|
24
24
|
},
|
25
25
|
"devDependencies": {
|
package/src/core/cache.ts
CHANGED
@@ -226,7 +226,10 @@ function callSubscriptions(
|
|
226
226
|
// - consistency
|
227
227
|
// - it's also weird, this is called from makeNetworkRequest, where
|
228
228
|
// we don't currently pass network request options
|
229
|
-
{
|
229
|
+
{
|
230
|
+
suspendIfInFlight: false,
|
231
|
+
throwOnNetworkError: false,
|
232
|
+
},
|
230
233
|
);
|
231
234
|
|
232
235
|
if (
|
package/src/core/read.ts
CHANGED
@@ -468,10 +468,19 @@ function writeQueryArgsToVariables(
|
|
468
468
|
}
|
469
469
|
|
470
470
|
export type NetworkRequestReaderOptions = {
|
471
|
-
suspendIfInFlight
|
472
|
-
throwOnNetworkError
|
471
|
+
suspendIfInFlight: boolean;
|
472
|
+
throwOnNetworkError: boolean;
|
473
473
|
};
|
474
474
|
|
475
|
+
export function getNetworkRequestOptionsWithDefaults(
|
476
|
+
networkRequestOptions?: Partial<NetworkRequestReaderOptions> | void,
|
477
|
+
): NetworkRequestReaderOptions {
|
478
|
+
return {
|
479
|
+
suspendIfInFlight: networkRequestOptions?.suspendIfInFlight ?? false,
|
480
|
+
throwOnNetworkError: networkRequestOptions?.throwOnNetworkError ?? true,
|
481
|
+
};
|
482
|
+
}
|
483
|
+
|
475
484
|
// TODO use a description of the params for this?
|
476
485
|
// TODO call stableStringifyArgs on the variable values, as well.
|
477
486
|
// This doesn't matter for now, since we are just using primitive values
|
@@ -15,7 +15,7 @@ export function FragmentReader<
|
|
15
15
|
React.FC<{}>
|
16
16
|
>;
|
17
17
|
additionalProps?: TProps;
|
18
|
-
networkRequestOptions?: NetworkRequestReaderOptions
|
18
|
+
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
19
19
|
}
|
20
20
|
: {
|
21
21
|
fragmentReference: FragmentReference<
|
@@ -23,12 +23,12 @@ export function FragmentReader<
|
|
23
23
|
React.FC<TProps>
|
24
24
|
>;
|
25
25
|
additionalProps: TProps;
|
26
|
-
networkRequestOptions?: NetworkRequestReaderOptions
|
26
|
+
networkRequestOptions?: Partial<NetworkRequestReaderOptions>;
|
27
27
|
},
|
28
28
|
): React.ReactNode {
|
29
29
|
const Component = useResult(
|
30
30
|
props.fragmentReference,
|
31
|
-
props.networkRequestOptions
|
31
|
+
props.networkRequestOptions,
|
32
32
|
);
|
33
33
|
return <Component {...props.additionalProps} />;
|
34
34
|
}
|
package/src/react/useResult.ts
CHANGED
@@ -2,14 +2,20 @@ import { useIsographEnvironment } from '../react/IsographEnvironmentProvider';
|
|
2
2
|
import { FragmentReference } from '../core/FragmentReference';
|
3
3
|
import { getOrCreateCachedComponent } from '../core/componentCache';
|
4
4
|
import { useReadAndSubscribe } from './useReadAndSubscribe';
|
5
|
-
import {
|
5
|
+
import {
|
6
|
+
getNetworkRequestOptionsWithDefaults,
|
7
|
+
NetworkRequestReaderOptions,
|
8
|
+
} from '../core/read';
|
6
9
|
import { getPromiseState, PromiseWrapper } from '../core/PromiseWrapper';
|
7
10
|
|
8
11
|
export function useResult<TReadFromStore extends Object, TClientFieldValue>(
|
9
12
|
fragmentReference: FragmentReference<TReadFromStore, TClientFieldValue>,
|
10
|
-
|
13
|
+
partialNetworkRequestOptions?: Partial<NetworkRequestReaderOptions> | void,
|
11
14
|
): TClientFieldValue {
|
12
15
|
const environment = useIsographEnvironment();
|
16
|
+
const networkRequestOptions = getNetworkRequestOptionsWithDefaults(
|
17
|
+
partialNetworkRequestOptions,
|
18
|
+
);
|
13
19
|
|
14
20
|
maybeUnwrapNetworkRequest(
|
15
21
|
fragmentReference.networkRequest,
|