ropegeo-common 1.16.0 → 1.16.1
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/README.md
CHANGED
|
@@ -326,7 +326,7 @@ Legend entries for page minimaps are keyed objects (`legend` on `PageMiniMap`);
|
|
|
326
326
|
|
|
327
327
|
| Name | Description | Import |
|
|
328
328
|
| --- | --- | --- |
|
|
329
|
-
| `RopeGeoDataLoader` | Single-request loader: `onlinePath` / `onlinePathParams`, optional `offlineData` (object
|
|
329
|
+
| `RopeGeoDataLoader` | Single-request loader: `onlinePath` / `onlinePathParams`, optional `offlineData` (object used as `data` immediately; no network), optional `timeoutAfterSeconds` and `isOnline`. Children receive `data`, `errors`, `timeoutCountdown` (numeric only while an online fetch is in flight, otherwise `null`), and `reload`. Reconnect refetch uses `dirtyWhileOffline` driven by a semantic key (no `refreshOnReconnect` prop). Also exports `Method`, `Service`, `SERVICE_BASE_URL`. | `import { RopeGeoDataLoader, Method, Service } from 'ropegeo-common/components'` |
|
|
330
330
|
| `RopeGeoPagedDataLoader` | Cursor-paginated list: same networking props as above; children get `loadNextPage`, `loadingNextPage`, `morePages`, plus `data`, `errors`, `timeoutCountdown`, `reload`. | `import { RopeGeoPagedDataLoader } from 'ropegeo-common/components'` |
|
|
331
331
|
| `RopeGeoProgressDataLoader` | Page-based “progress” fetch: batches additional pages until `total` is satisfied; children get `received`, `total`, `data`, `errors`, `timeoutCountdown`, `reload`. | `import { RopeGeoProgressDataLoader } from 'ropegeo-common/components'` |
|
|
332
332
|
|
|
@@ -31,15 +31,10 @@ export type RopeGeoDataLoaderProps<T = unknown> = {
|
|
|
31
31
|
*/
|
|
32
32
|
isOnline?: boolean;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* `Could not read file at {path}` is set and the loader falls back to {@link onlinePath} when online.
|
|
34
|
+
* When set, this value is used as `data` immediately (no network). Callers that load from disk
|
|
35
|
+
* should read and parse the file themselves, then pass the resulting object here.
|
|
37
36
|
*/
|
|
38
|
-
offlineData?: T
|
|
39
|
-
/**
|
|
40
|
-
* Required when `offlineData` is a string. Reads file contents as UTF-8 text for JSON parsing.
|
|
41
|
-
*/
|
|
42
|
-
readOfflineFile?: (path: string) => Promise<string>;
|
|
37
|
+
offlineData?: T;
|
|
43
38
|
children: (args: {
|
|
44
39
|
data: T | null;
|
|
45
40
|
errors: Error | null;
|
|
@@ -52,5 +47,5 @@ export type RopeGeoDataLoaderProps<T = unknown> = {
|
|
|
52
47
|
reload: () => void;
|
|
53
48
|
}) => ReactNode;
|
|
54
49
|
};
|
|
55
|
-
export declare function RopeGeoDataLoader<T = unknown>({ service, method, onlinePath, onlinePathParams, queryParams, body, timeoutAfterSeconds, isOnline, offlineData,
|
|
50
|
+
export declare function RopeGeoDataLoader<T = unknown>({ service, method, onlinePath, onlinePathParams, queryParams, body, timeoutAfterSeconds, isOnline, offlineData, children, }: RopeGeoDataLoaderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
56
51
|
//# sourceMappingURL=RopeGeoDataLoader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RopeGeoDataLoader.d.ts","sourceRoot":"","sources":["../../src/components/RopeGeoDataLoader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAavC,eAAO,MAAM,OAAO;;CAEV,CAAC;AACX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE7D,eAAO,MAAM,MAAM;;;;;CAKT,CAAC;AACX,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAEpD,CAAC;
|
|
1
|
+
{"version":3,"file":"RopeGeoDataLoader.d.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AC;AAEF,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAAE,EAC7C,OAAO,EACP,MAAM,EACN,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,IAAI,EACJ,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,QAAQ,GACT,EAAE,sBAAsB,CAAC,CAAC,CAAC,2CAwT3B"}
|
|
@@ -57,18 +57,14 @@ function dataLoaderReconnectSemanticKey(service, method, onlinePath, pathParamsK
|
|
|
57
57
|
function offlineDataKeyPart(offlineData) {
|
|
58
58
|
if (offlineData === undefined)
|
|
59
59
|
return "";
|
|
60
|
-
if (typeof offlineData === "string")
|
|
61
|
-
return `|file:${offlineData}`;
|
|
62
60
|
return `|obj:${JSON.stringify(offlineData)}`;
|
|
63
61
|
}
|
|
64
|
-
function RopeGeoDataLoader({ service, method, onlinePath, onlinePathParams, queryParams, body, timeoutAfterSeconds, isOnline, offlineData,
|
|
62
|
+
function RopeGeoDataLoader({ service, method, onlinePath, onlinePathParams, queryParams, body, timeoutAfterSeconds, isOnline, offlineData, children, }) {
|
|
65
63
|
const [data, setData] = (0, react_1.useState)(null);
|
|
66
64
|
const [errors, setErrors] = (0, react_1.useState)(null);
|
|
67
65
|
const [timeoutCountdown, setTimeoutCountdown] = (0, react_1.useState)(null);
|
|
68
66
|
const [reloadTick, setReloadTick] = (0, react_1.useState)(0);
|
|
69
67
|
const pendingReloadRef = (0, react_1.useRef)(false);
|
|
70
|
-
/** `null` = not using file path, `'pending'`, `'ok'`, `'failed'` */
|
|
71
|
-
const [offlineFileStatus, setOfflineFileStatus] = (0, react_1.useState)(null);
|
|
72
68
|
const errorsRef = (0, react_1.useRef)(errors);
|
|
73
69
|
const hasCommittedRef = (0, react_1.useRef)(false);
|
|
74
70
|
errorsRef.current = errors;
|
|
@@ -108,61 +104,17 @@ function RopeGeoDataLoader({ service, method, onlinePath, onlinePathParams, quer
|
|
|
108
104
|
setReloadTick((n) => n + 1);
|
|
109
105
|
}, [isOnline]);
|
|
110
106
|
const lastRequestKeyRef = (0, react_1.useRef)("");
|
|
111
|
-
/**
|
|
107
|
+
/** `offlineData` object — immediate `data`, no network. */
|
|
112
108
|
(0, react_1.useEffect)(() => {
|
|
113
|
-
if (offlineData
|
|
109
|
+
if (offlineData === undefined) {
|
|
114
110
|
return;
|
|
115
111
|
}
|
|
116
|
-
setOfflineFileStatus(null);
|
|
117
112
|
setData(offlineData);
|
|
118
113
|
setErrors(null);
|
|
119
114
|
hasCommittedRef.current = true;
|
|
120
115
|
dirtyWhileOfflineRef.current = false;
|
|
121
116
|
semanticSnapshotRef.current = null;
|
|
122
117
|
}, [offlineData]);
|
|
123
|
-
/** String path: read file, then maybe fall back to online. */
|
|
124
|
-
(0, react_1.useEffect)(() => {
|
|
125
|
-
if (typeof offlineData !== "string") {
|
|
126
|
-
setOfflineFileStatus(null);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
let cancelled = false;
|
|
130
|
-
setOfflineFileStatus("pending");
|
|
131
|
-
setData(null);
|
|
132
|
-
setErrors(null);
|
|
133
|
-
hasCommittedRef.current = false;
|
|
134
|
-
if (readOfflineFile == null) {
|
|
135
|
-
setErrors(new Error("readOfflineFile is required when offlineData is a filesystem path"));
|
|
136
|
-
setOfflineFileStatus("failed");
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
void (async () => {
|
|
140
|
-
try {
|
|
141
|
-
const text = await readOfflineFile(offlineData);
|
|
142
|
-
const raw = JSON.parse(text);
|
|
143
|
-
const parsed = models_1.Result.fromResponseBody(raw);
|
|
144
|
-
if (!cancelled) {
|
|
145
|
-
setData(parsed.result);
|
|
146
|
-
setErrors(null);
|
|
147
|
-
hasCommittedRef.current = true;
|
|
148
|
-
setOfflineFileStatus("ok");
|
|
149
|
-
dirtyWhileOfflineRef.current = false;
|
|
150
|
-
semanticSnapshotRef.current = null;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
if (!cancelled) {
|
|
155
|
-
setErrors(new Error(`Could not read file at ${offlineData}`));
|
|
156
|
-
setData(null);
|
|
157
|
-
hasCommittedRef.current = false;
|
|
158
|
-
setOfflineFileStatus("failed");
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
})();
|
|
162
|
-
return () => {
|
|
163
|
-
cancelled = true;
|
|
164
|
-
};
|
|
165
|
-
}, [offlineData, readOfflineFile]);
|
|
166
118
|
(0, react_1.useEffect)(() => {
|
|
167
119
|
const online = isOnline !== false;
|
|
168
120
|
const prevOnline = prevIsOnlineRef.current;
|
|
@@ -178,19 +130,8 @@ function RopeGeoDataLoader({ service, method, onlinePath, onlinePathParams, quer
|
|
|
178
130
|
dirtyWhileOfflineRef.current = true;
|
|
179
131
|
}
|
|
180
132
|
}
|
|
181
|
-
/**
|
|
182
|
-
if (offlineData
|
|
183
|
-
prevIsOnlineRef.current = online;
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
/** File path: wait for read outcome; `ok` keeps local data; only `failed` falls through to online fetch. */
|
|
187
|
-
if (typeof offlineData === "string" && offlineFileStatus === "ok") {
|
|
188
|
-
prevIsOnlineRef.current = online;
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (typeof offlineData === "string" &&
|
|
192
|
-
offlineFileStatus !== "failed" &&
|
|
193
|
-
offlineFileStatus !== "ok") {
|
|
133
|
+
/** Object `offlineData`: dedicated effect owns `data`; never hit the network here. */
|
|
134
|
+
if (offlineData !== undefined) {
|
|
194
135
|
prevIsOnlineRef.current = online;
|
|
195
136
|
return;
|
|
196
137
|
}
|
|
@@ -366,7 +307,6 @@ function RopeGeoDataLoader({ service, method, onlinePath, onlinePathParams, quer
|
|
|
366
307
|
requestKey,
|
|
367
308
|
reloadTick,
|
|
368
309
|
offlineData,
|
|
369
|
-
offlineFileStatus,
|
|
370
310
|
reconnectSemanticKey,
|
|
371
311
|
queryParams,
|
|
372
312
|
]);
|