@isograph/react 0.0.0-main-a3a330ff → 0.0.0-main-37985805
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/cache.d.ts +6 -0
- package/dist/cache.js +2 -1
- package/dist/componentCache.d.ts +1 -1
- package/dist/componentCache.js +3 -1
- package/dist/index.js +2 -2
- package/package.json +3 -3
- package/src/cache.ts +1 -1
- package/src/componentCache.ts +2 -2
- package/src/index.tsx +0 -2
package/dist/cache.d.ts
CHANGED
@@ -6,6 +6,12 @@ declare global {
|
|
6
6
|
__LOG: boolean;
|
7
7
|
}
|
8
8
|
}
|
9
|
+
/**
|
10
|
+
* Creates a copy of the provided value, ensuring any nested objects have their
|
11
|
+
* keys sorted such that equivalent values would have identical JSON.stringify
|
12
|
+
* results.
|
13
|
+
*/
|
14
|
+
export declare function stableCopy<T>(value: T): T;
|
9
15
|
type IsoResolver = IsographEntrypoint<any, any, any>;
|
10
16
|
export declare function getOrCreateCacheForArtifact<T>(artifact: IsographEntrypoint<any, any, T>, variables: object): ParentCache<PromiseWrapper<T>>;
|
11
17
|
declare let network: ((queryText: string, variables: object) => Promise<any>) | null;
|
package/dist/cache.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.SECOND_SPLIT_KEY = exports.FIRST_SPLIT_KEY = exports.getParentRecordKey = exports.onNextChange = exports.subscribe = exports.clearStore = exports.getStore = exports.ROOT_ID = exports.makeNetworkRequest = exports.setNetwork = exports.getOrCreateCacheForArtifact = void 0;
|
3
|
+
exports.SECOND_SPLIT_KEY = exports.FIRST_SPLIT_KEY = exports.getParentRecordKey = exports.onNextChange = exports.subscribe = exports.clearStore = exports.getStore = exports.ROOT_ID = exports.makeNetworkRequest = exports.setNetwork = exports.getOrCreateCacheForArtifact = exports.stableCopy = void 0;
|
4
4
|
const react_disposable_state_1 = require("@isograph/react-disposable-state");
|
5
5
|
const PromiseWrapper_1 = require("./PromiseWrapper");
|
6
6
|
const cache = {};
|
@@ -38,6 +38,7 @@ function stableCopy(value) {
|
|
38
38
|
}
|
39
39
|
return stable;
|
40
40
|
}
|
41
|
+
exports.stableCopy = stableCopy;
|
41
42
|
function getOrCreateCacheForArtifact(artifact, variables) {
|
42
43
|
const cacheKey = artifact.queryText + JSON.stringify(stableCopy(variables));
|
43
44
|
const factory = () => makeNetworkRequest(artifact, variables);
|
package/dist/componentCache.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { ReaderArtifact, RefetchQueryArtifactWrapper } from "./index";
|
3
3
|
import { DataId } from "./cache";
|
4
|
-
export declare function getOrCreateCachedComponent(root: DataId, componentName: string,
|
4
|
+
export declare function getOrCreateCachedComponent(root: DataId, componentName: string, readerArtifact: ReaderArtifact<any, any, any>, variables: {
|
5
5
|
[key: string]: string;
|
6
6
|
}, resolverRefetchQueries: RefetchQueryArtifactWrapper[]): import("react").FC<any>;
|
package/dist/componentCache.js
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getOrCreateCachedComponent = void 0;
|
4
4
|
const index_1 = require("./index");
|
5
|
+
const cache_1 = require("./cache");
|
5
6
|
const cachedComponentsById = {};
|
6
|
-
function getOrCreateCachedComponent(root, componentName,
|
7
|
+
function getOrCreateCachedComponent(root, componentName, readerArtifact, variables, resolverRefetchQueries) {
|
7
8
|
var _a, _b, _c;
|
9
|
+
const stringifiedArgs = JSON.stringify((0, cache_1.stableCopy)(variables));
|
8
10
|
cachedComponentsById[root] = (_a = cachedComponentsById[root]) !== null && _a !== void 0 ? _a : {};
|
9
11
|
const componentsByName = cachedComponentsById[root];
|
10
12
|
componentsByName[componentName] = (_b = componentsByName[componentName]) !== null && _b !== void 0 ? _b : {};
|
package/dist/index.js
CHANGED
@@ -57,7 +57,7 @@ function read(fragmentReference) {
|
|
57
57
|
}
|
58
58
|
else if (variant.kind === "Component") {
|
59
59
|
// @ts-ignore
|
60
|
-
return (0, componentCache_1.getOrCreateCachedComponent)(fragmentReference.root, variant.componentName,
|
60
|
+
return (0, componentCache_1.getOrCreateCachedComponent)(fragmentReference.root, variant.componentName, fragmentReference.readerArtifact, (_b = fragmentReference.variables) !== null && _b !== void 0 ? _b : {}, fragmentReference.nestedRefetchQueries);
|
61
61
|
}
|
62
62
|
// Why can't Typescript realize that this is unreachable??
|
63
63
|
throw new Error("This is unreachable");
|
@@ -248,7 +248,7 @@ function readData(ast, root, variables, nestedRefetchQueries) {
|
|
248
248
|
}
|
249
249
|
}
|
250
250
|
else if (variant.kind === "Component") {
|
251
|
-
target[field.alias] = (0, componentCache_1.getOrCreateCachedComponent)(root, variant.componentName,
|
251
|
+
target[field.alias] = (0, componentCache_1.getOrCreateCachedComponent)(root, variant.componentName, field.readerArtifact, variables, resolverRefetchQueries);
|
252
252
|
}
|
253
253
|
break;
|
254
254
|
}
|
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-37985805",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"prepack": "yarn run test && yarn run compile"
|
16
16
|
},
|
17
17
|
"dependencies": {
|
18
|
-
"@isograph/disposable-types": "0.0.0-main-
|
19
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
18
|
+
"@isograph/disposable-types": "0.0.0-main-37985805",
|
19
|
+
"@isograph/react-disposable-state": "0.0.0-main-37985805",
|
20
20
|
"react": "^18.2.0"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
package/src/cache.ts
CHANGED
@@ -45,7 +45,7 @@ function getOrCreateCache<T>(
|
|
45
45
|
* keys sorted such that equivalent values would have identical JSON.stringify
|
46
46
|
* results.
|
47
47
|
*/
|
48
|
-
function stableCopy<T>(value: T): T {
|
48
|
+
export function stableCopy<T>(value: T): T {
|
49
49
|
if (!value || typeof value !== "object") {
|
50
50
|
return value;
|
51
51
|
}
|
package/src/componentCache.ts
CHANGED
@@ -3,7 +3,7 @@ import {
|
|
3
3
|
RefetchQueryArtifactWrapper,
|
4
4
|
readButDoNotEvaluate,
|
5
5
|
} from "./index";
|
6
|
-
import { DataId } from "./cache";
|
6
|
+
import { DataId, stableCopy } from "./cache";
|
7
7
|
|
8
8
|
type ComponentName = string;
|
9
9
|
type StringifiedArgs = string;
|
@@ -15,11 +15,11 @@ const cachedComponentsById: {
|
|
15
15
|
export function getOrCreateCachedComponent(
|
16
16
|
root: DataId,
|
17
17
|
componentName: string,
|
18
|
-
stringifiedArgs: string,
|
19
18
|
readerArtifact: ReaderArtifact<any, any, any>,
|
20
19
|
variables: { [key: string]: string },
|
21
20
|
resolverRefetchQueries: RefetchQueryArtifactWrapper[]
|
22
21
|
) {
|
22
|
+
const stringifiedArgs = JSON.stringify(stableCopy(variables));
|
23
23
|
cachedComponentsById[root] = cachedComponentsById[root] ?? {};
|
24
24
|
const componentsByName = cachedComponentsById[root];
|
25
25
|
componentsByName[componentName] = componentsByName[componentName] ?? {};
|
package/src/index.tsx
CHANGED
@@ -256,7 +256,6 @@ export function read<
|
|
256
256
|
return getOrCreateCachedComponent(
|
257
257
|
fragmentReference.root,
|
258
258
|
variant.componentName,
|
259
|
-
"TODO",
|
260
259
|
fragmentReference.readerArtifact,
|
261
260
|
fragmentReference.variables ?? {},
|
262
261
|
fragmentReference.nestedRefetchQueries
|
@@ -519,7 +518,6 @@ function readData<TReadFromStore>(
|
|
519
518
|
target[field.alias] = getOrCreateCachedComponent(
|
520
519
|
root,
|
521
520
|
variant.componentName,
|
522
|
-
"TODO",
|
523
521
|
field.readerArtifact,
|
524
522
|
variables,
|
525
523
|
resolverRefetchQueries
|