@isograph/react 0.0.0-main-88b54795 → 0.0.0-main-a8fa50f7
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.
@@ -4,6 +4,8 @@ exports.useSkipLimitPagination = void 0;
|
|
4
4
|
const IsographEnvironmentProvider_1 = require("../react/IsographEnvironmentProvider");
|
5
5
|
const useResult_1 = require("../react/useResult");
|
6
6
|
const read_1 = require("../core/read");
|
7
|
+
const cache_1 = require("../core/cache");
|
8
|
+
const react_1 = require("react");
|
7
9
|
const react_disposable_state_1 = require("@isograph/react-disposable-state");
|
8
10
|
const reference_counted_pointer_1 = require("@isograph/reference-counted-pointer");
|
9
11
|
const PromiseWrapper_1 = require("../core/PromiseWrapper");
|
@@ -42,7 +44,11 @@ function useSkipLimitPagination(loadableField) {
|
|
42
44
|
(0, useResult_1.maybeUnwrapNetworkRequest)(fragmentReference.networkRequest, networkRequestOptions);
|
43
45
|
const data = (0, read_1.readButDoNotEvaluate)(environment, fragmentReference, networkRequestOptions);
|
44
46
|
const readerWithRefetchQueries = (0, PromiseWrapper_1.readPromise)(fragmentReference.readerWithRefetchQueries);
|
45
|
-
|
47
|
+
const firstParameter = {
|
48
|
+
data,
|
49
|
+
parameters: fragmentReference.variables,
|
50
|
+
};
|
51
|
+
return readerWithRefetchQueries.readerArtifact.resolver(firstParameter, undefined);
|
46
52
|
});
|
47
53
|
const items = flatten(results);
|
48
54
|
return items;
|
@@ -70,6 +76,7 @@ function useSkipLimitPagination(loadableField) {
|
|
70
76
|
];
|
71
77
|
setState(totalItemCleanupPair);
|
72
78
|
};
|
79
|
+
const [, rerender] = (0, react_1.useState)({});
|
73
80
|
const loadedReferences = state === react_disposable_state_1.UNASSIGNED_STATE ? [] : state;
|
74
81
|
if (loadedReferences.length === 0) {
|
75
82
|
return {
|
@@ -88,6 +95,10 @@ function useSkipLimitPagination(loadableField) {
|
|
88
95
|
switch (networkRequestStatus.kind) {
|
89
96
|
case 'Pending': {
|
90
97
|
const completedFragmentReferences = loadedReferences.slice(0, loadedReferences.length - 1);
|
98
|
+
const unsubscribe = (0, cache_1.subscribeToAnyChange)(environment, () => {
|
99
|
+
unsubscribe();
|
100
|
+
rerender({});
|
101
|
+
});
|
91
102
|
return {
|
92
103
|
kind: 'Pending',
|
93
104
|
pendingFragment: mostRecentFragmentReference,
|
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-a8fa50f7",
|
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-a8fa50f7",
|
21
|
+
"@isograph/react-disposable-state": "0.0.0-main-a8fa50f7",
|
22
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-a8fa50f7"
|
23
23
|
},
|
24
24
|
"peerDependencies": {
|
25
25
|
"react": "18.2.0"
|
@@ -4,6 +4,8 @@ import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
4
4
|
import { FragmentReference } from '../core/FragmentReference';
|
5
5
|
import { maybeUnwrapNetworkRequest } from '../react/useResult';
|
6
6
|
import { readButDoNotEvaluate } from '../core/read';
|
7
|
+
import { subscribeToAnyChange } from '../core/cache';
|
8
|
+
import { useState } from 'react';
|
7
9
|
import {
|
8
10
|
UNASSIGNED_STATE,
|
9
11
|
useUpdatableDisposableState,
|
@@ -105,8 +107,13 @@ export function useSkipLimitPagination<
|
|
105
107
|
fragmentReference.readerWithRefetchQueries,
|
106
108
|
);
|
107
109
|
|
110
|
+
const firstParameter = {
|
111
|
+
data,
|
112
|
+
parameters: fragmentReference.variables,
|
113
|
+
};
|
114
|
+
|
108
115
|
return readerWithRefetchQueries.readerArtifact.resolver(
|
109
|
-
|
116
|
+
firstParameter,
|
110
117
|
undefined,
|
111
118
|
) as ReadonlyArray<any>;
|
112
119
|
});
|
@@ -155,6 +162,8 @@ export function useSkipLimitPagination<
|
|
155
162
|
setState(totalItemCleanupPair);
|
156
163
|
};
|
157
164
|
|
165
|
+
const [, rerender] = useState({});
|
166
|
+
|
158
167
|
const loadedReferences = state === UNASSIGNED_STATE ? [] : state;
|
159
168
|
if (loadedReferences.length === 0) {
|
160
169
|
return {
|
@@ -182,6 +191,12 @@ export function useSkipLimitPagination<
|
|
182
191
|
0,
|
183
192
|
loadedReferences.length - 1,
|
184
193
|
);
|
194
|
+
|
195
|
+
const unsubscribe = subscribeToAnyChange(environment, () => {
|
196
|
+
unsubscribe();
|
197
|
+
rerender({});
|
198
|
+
});
|
199
|
+
|
185
200
|
return {
|
186
201
|
kind: 'Pending',
|
187
202
|
pendingFragment: mostRecentFragmentReference,
|