@bgub/fig 2.0.0 → 2.1.0
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/CHANGELOG.md +86 -0
- package/README.md +21 -22
- package/dist/{element-B4LrR2ZB.d.ts → element-DT9ziqWN.d.ts} +43 -14
- package/dist/{element-j7AKp0nu.js → element-DpXdLgOZ.js} +6 -68
- package/dist/element-DpXdLgOZ.js.map +1 -0
- package/dist/{hooks-QSWYd3Vl.d.ts → hooks-GeZ4mX7W.d.ts} +13 -19
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/internal.d.ts +7 -9
- package/dist/internal.js +8 -4
- package/dist/internal.js.map +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/dist/payload-format-B9UbNtxo.js.map +1 -1
- package/dist/payload.d.ts +1 -1
- package/dist/payload.js +2 -2
- package/{dist-development/resource-YO25HR7G.js → dist/resource-DEDmLSNk.js} +5 -18
- package/dist/resource-DEDmLSNk.js.map +1 -0
- package/dist/{transition-DJfG2ZSm.js → transition-BFLGYE4q.js} +366 -79
- package/dist/transition-BFLGYE4q.js.map +1 -0
- package/dist-development/{element-DzmNF67v.js → element-DbzJUf5a.js} +6 -68
- package/dist-development/element-DbzJUf5a.js.map +1 -0
- package/dist-development/index.js +4 -4
- package/dist-development/internal.js +8 -4
- package/dist-development/internal.js.map +1 -1
- package/dist-development/jsx-runtime.js +1 -1
- package/dist-development/payload-format-B9UbNtxo.js.map +1 -1
- package/dist-development/payload.js +2 -2
- package/{dist/resource-Lwjz_b4h.js → dist-development/resource-BZOBllE_.js} +5 -18
- package/dist-development/resource-BZOBllE_.js.map +1 -0
- package/dist-development/{transition-CrIF0Kz_.js → transition-CWjp9qRO.js} +363 -78
- package/dist-development/transition-CWjp9qRO.js.map +1 -0
- package/package.json +1 -1
- package/dist/element-j7AKp0nu.js.map +0 -1
- package/dist/resource-Lwjz_b4h.js.map +0 -1
- package/dist/transition-DJfG2ZSm.js.map +0 -1
- package/dist-development/element-DzmNF67v.js.map +0 -1
- package/dist-development/resource-YO25HR7G.js.map +0 -1
- package/dist-development/transition-CrIF0Kz_.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { y as isThenable$1 } from "./resource-Lwjz_b4h.js";
|
|
1
|
+
import { y as isThenable$1 } from "./resource-DEDmLSNk.js";
|
|
3
2
|
//#region src/context.ts
|
|
4
3
|
/** The Fig context symbol. */
|
|
5
4
|
const FigContextSymbol = Symbol.for("fig.context");
|
|
@@ -15,6 +14,61 @@ function isContext(value) {
|
|
|
15
14
|
return typeof value === "function" && "$$typeof" in value && value.$$typeof === FigContextSymbol;
|
|
16
15
|
}
|
|
17
16
|
//#endregion
|
|
17
|
+
//#region src/data.ts
|
|
18
|
+
const LoadContextCapabilitiesSymbol = Symbol.for("fig.data-load-context");
|
|
19
|
+
/** Define load context capabilities. */
|
|
20
|
+
function defineLoadContextCapabilities(context, capabilities) {
|
|
21
|
+
Object.defineProperty(context, LoadContextCapabilitiesSymbol, {
|
|
22
|
+
configurable: true,
|
|
23
|
+
enumerable: false,
|
|
24
|
+
value: capabilities
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Load context capabilities. */
|
|
28
|
+
function loadContextCapabilities(context) {
|
|
29
|
+
return context[LoadContextCapabilitiesSymbol];
|
|
30
|
+
}
|
|
31
|
+
const objectDataErrors = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
let currentDataStore$1 = null;
|
|
33
|
+
/** Captures an optional data store for synchronous scope re-entry. */
|
|
34
|
+
function getCurrentDataStore() {
|
|
35
|
+
return currentDataStore$1;
|
|
36
|
+
}
|
|
37
|
+
/** Resolves current data store. */
|
|
38
|
+
function resolveCurrentDataStore(message = "Data resource APIs require a Fig data store.") {
|
|
39
|
+
if (currentDataStore$1 === null) throw new Error(message);
|
|
40
|
+
return currentDataStore$1;
|
|
41
|
+
}
|
|
42
|
+
/** Sets current data store. */
|
|
43
|
+
function setCurrentDataStore(store) {
|
|
44
|
+
const previousStore = currentDataStore$1;
|
|
45
|
+
currentDataStore$1 = store;
|
|
46
|
+
return previousStore;
|
|
47
|
+
}
|
|
48
|
+
/** Marks data resource error. */
|
|
49
|
+
function markDataResourceError(error, key) {
|
|
50
|
+
if (!isAttributableError(error)) return;
|
|
51
|
+
let keys = objectDataErrors.get(error);
|
|
52
|
+
if (keys === void 0) {
|
|
53
|
+
keys = [];
|
|
54
|
+
objectDataErrors.set(error, keys);
|
|
55
|
+
}
|
|
56
|
+
if (keys.some((existing) => sameDataResourceKey(existing, key))) return;
|
|
57
|
+
keys.push(key);
|
|
58
|
+
}
|
|
59
|
+
/** Data resource keys for error. */
|
|
60
|
+
function dataResourceKeysForError(error) {
|
|
61
|
+
if (!isAttributableError(error)) return void 0;
|
|
62
|
+
const keys = objectDataErrors.get(error);
|
|
63
|
+
return keys === void 0 || keys.length === 0 ? void 0 : [...keys];
|
|
64
|
+
}
|
|
65
|
+
function sameDataResourceKey(a, b) {
|
|
66
|
+
return a.length === b.length && a.every((value, index) => Object.is(value, b[index]));
|
|
67
|
+
}
|
|
68
|
+
function isAttributableError(value) {
|
|
69
|
+
return (typeof value === "object" || typeof value === "function") && value !== null;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
18
72
|
//#region src/data-store.ts
|
|
19
73
|
const DataResourceSymbol = Symbol.for("fig.data-resource");
|
|
20
74
|
const DataStoreFactorySymbol = Symbol.for("fig.data-store-factory");
|
|
@@ -28,34 +82,13 @@ function dataResource(options) {
|
|
|
28
82
|
$$typeof: DataResourceSymbol,
|
|
29
83
|
[DataStoreFactorySymbol]: dataStoreFactory,
|
|
30
84
|
debugArgs: options.debugArgs,
|
|
85
|
+
equals: options.equals,
|
|
86
|
+
inactiveRetentionMs: options.inactiveRetentionMs,
|
|
31
87
|
key: options.key,
|
|
32
|
-
load: options.load
|
|
88
|
+
load: options.load,
|
|
89
|
+
watch: options.watch
|
|
33
90
|
};
|
|
34
91
|
}
|
|
35
|
-
/** Ensures data. */
|
|
36
|
-
function ensureData(resource, ...args) {
|
|
37
|
-
return resolveDataMutationStore("ensureData").ensureData(resource, ...args);
|
|
38
|
-
}
|
|
39
|
-
/** Invalidates data. */
|
|
40
|
-
function invalidateData(resource, ...args) {
|
|
41
|
-
resolveDataMutationStore("invalidateData").invalidateData(resource, ...args);
|
|
42
|
-
}
|
|
43
|
-
/** Invalidates data error. */
|
|
44
|
-
function invalidateDataError(error) {
|
|
45
|
-
return resolveDataMutationStore("invalidateDataError").invalidateDataError(error);
|
|
46
|
-
}
|
|
47
|
-
/** Invalidates data key. */
|
|
48
|
-
function invalidateDataKey(key) {
|
|
49
|
-
resolveDataMutationStore("invalidateDataKey").invalidateDataKey(key);
|
|
50
|
-
}
|
|
51
|
-
/** Invalidates data prefix. */
|
|
52
|
-
function invalidateDataPrefix(prefix) {
|
|
53
|
-
resolveDataMutationStore("invalidateDataPrefix").invalidateDataPrefix(prefix);
|
|
54
|
-
}
|
|
55
|
-
/** Refreshes data. */
|
|
56
|
-
function refreshData(resource, ...args) {
|
|
57
|
-
return resolveDataMutationStore("refreshData").refreshData(resource, ...args);
|
|
58
|
-
}
|
|
59
92
|
/** Reads data store. */
|
|
60
93
|
function readDataStore() {
|
|
61
94
|
return resolveCurrentDataStore("readDataStore() must be called synchronously while Fig is executing — during render, an event handler, an action, or an effect. Capture the handle there and use it after awaits.");
|
|
@@ -65,8 +98,10 @@ function createDataStore(options = {}) {
|
|
|
65
98
|
const state = { host: null };
|
|
66
99
|
const store = createRendererDataStore({
|
|
67
100
|
getLane: () => state.host === null ? null : state.host.getLane(),
|
|
68
|
-
|
|
69
|
-
|
|
101
|
+
schedule: (owner, lane) => state.host?.schedule(owner, lane),
|
|
102
|
+
get watchSources() {
|
|
103
|
+
return state.host?.watchSources === true;
|
|
104
|
+
}
|
|
70
105
|
});
|
|
71
106
|
Object.defineProperty(store, DataStoreControllerSymbol, { value: state });
|
|
72
107
|
if (options.initialData !== void 0) store.hydrate(options.initialData);
|
|
@@ -78,16 +113,13 @@ function isDataStoreController(value) {
|
|
|
78
113
|
}
|
|
79
114
|
/** Attach data store. */
|
|
80
115
|
function attachDataStore(controller, host, initialData) {
|
|
81
|
-
if (
|
|
116
|
+
if (initialData !== void 0) throw new Error("Pass initialData to createDataStore(), not the renderer, when adopting a data store.");
|
|
82
117
|
const state = controller[DataStoreControllerSymbol];
|
|
83
118
|
if (state === void 0) throw new Error("dataStore must be created with createDataStore().");
|
|
84
119
|
if (state.host !== null) throw new Error("A data store can only be adopted by one Fig renderer.");
|
|
85
120
|
state.host = host;
|
|
86
121
|
return controller;
|
|
87
122
|
}
|
|
88
|
-
function resolveDataMutationStore(name) {
|
|
89
|
-
return resolveCurrentDataStore(`${name}() must be called synchronously while Fig is executing — during render, an event handler, an action, or an effect. Capture readDataStore() (or root.data) synchronously and call the handle instead.`);
|
|
90
|
-
}
|
|
91
123
|
/** Creates renderer data store. */
|
|
92
124
|
function createRendererDataStore(host) {
|
|
93
125
|
return new DefaultDataStore(host);
|
|
@@ -101,13 +133,12 @@ var DefaultDataStore = class {
|
|
|
101
133
|
entries = /* @__PURE__ */ new Map();
|
|
102
134
|
inactiveRetentionMs;
|
|
103
135
|
ownerKeys = /* @__PURE__ */ new WeakMap();
|
|
104
|
-
partitionKey;
|
|
105
136
|
preloadRetentionMs;
|
|
106
137
|
disposed = false;
|
|
138
|
+
pendingWatchReconciles = null;
|
|
107
139
|
constructor(host) {
|
|
108
140
|
this.host = host;
|
|
109
141
|
this.inactiveRetentionMs = host.inactiveRetentionMs ?? DEFAULT_INACTIVE_RETENTION_MS;
|
|
110
|
-
this.partitionKey = host.partition === void 0 ? "" : encodeValue(host.partition, createEncodePath("partition"));
|
|
111
142
|
this.preloadRetentionMs = host.preloadRetentionMs ?? DEFAULT_PRELOAD_RETENTION_MS;
|
|
112
143
|
}
|
|
113
144
|
areDataDependenciesConsistent(reads) {
|
|
@@ -135,11 +166,16 @@ var DefaultDataStore = class {
|
|
|
135
166
|
if (entry !== void 0) {
|
|
136
167
|
this.clearInactiveTimer(entry);
|
|
137
168
|
entry.subscribers.add(owner);
|
|
169
|
+
if (reads !== void 0) entry.retainers?.delete(reads);
|
|
138
170
|
this.notifyEntryChange(entry);
|
|
139
171
|
}
|
|
140
172
|
}
|
|
141
173
|
}
|
|
142
174
|
if (orphanCandidates !== null) for (const entry of orphanCandidates) this.abortOrphanedLoad(entry);
|
|
175
|
+
if (nextKeys !== null) for (const key of nextKeys) {
|
|
176
|
+
const entry = this.entries.get(key);
|
|
177
|
+
if (entry !== void 0) this.scheduleWatchReconcile(entry);
|
|
178
|
+
}
|
|
143
179
|
const consistent = reads === void 0 || this.areDataDependenciesConsistent(reads);
|
|
144
180
|
reads?.clear();
|
|
145
181
|
return consistent;
|
|
@@ -158,7 +194,10 @@ var DefaultDataStore = class {
|
|
|
158
194
|
if (entry === void 0) continue;
|
|
159
195
|
entry.subscribers.delete(owner);
|
|
160
196
|
this.notifyEntryChange(entry);
|
|
161
|
-
if (retainedKeys?.has(key) !== true)
|
|
197
|
+
if (retainedKeys?.has(key) !== true) {
|
|
198
|
+
this.scheduleInactiveCleanup(entry);
|
|
199
|
+
this.scheduleWatchReconcile(entry);
|
|
200
|
+
}
|
|
162
201
|
}
|
|
163
202
|
}
|
|
164
203
|
collectSubscribedEntries(keys, into) {
|
|
@@ -173,8 +212,8 @@ var DefaultDataStore = class {
|
|
|
173
212
|
return into;
|
|
174
213
|
}
|
|
175
214
|
abortOrphanedLoad(entry) {
|
|
176
|
-
if (this.entries.get(entry.
|
|
177
|
-
if (entry
|
|
215
|
+
if (this.entries.get(entry.canonicalKey) !== entry) return;
|
|
216
|
+
if (isHeld(entry) || entry.preloadTimer !== null || entry.pending === null || entryHasValue(entry)) return;
|
|
178
217
|
this.evictEntry(entry, "evicted");
|
|
179
218
|
}
|
|
180
219
|
dispose() {
|
|
@@ -187,27 +226,39 @@ var DefaultDataStore = class {
|
|
|
187
226
|
}
|
|
188
227
|
}
|
|
189
228
|
hydrate(entries) {
|
|
229
|
+
this.hydrateEntries(entries, true);
|
|
230
|
+
}
|
|
231
|
+
hydrateMissing(entries) {
|
|
232
|
+
this.hydrateEntries(entries, false);
|
|
233
|
+
}
|
|
234
|
+
hydrateEntries(entries, replaceValues) {
|
|
190
235
|
if (this.disposed) return;
|
|
191
236
|
for (const hydrated of entries) {
|
|
192
237
|
if (this.disposed) return;
|
|
193
238
|
const normalized = normalizeKey(hydrated.key);
|
|
194
|
-
const storeKey =
|
|
239
|
+
const storeKey = normalized.canonical;
|
|
195
240
|
const current = this.entries.get(storeKey);
|
|
196
241
|
if (current !== void 0) {
|
|
197
|
-
this.hydrateEntry(current, normalized.key, hydrated.value);
|
|
242
|
+
if (replaceValues || !entryHasValue(current)) this.hydrateEntry(current, normalized.key, hydrated.value);
|
|
198
243
|
continue;
|
|
199
244
|
}
|
|
200
|
-
const entry = this.createEntry(normalized,
|
|
245
|
+
const entry = this.createEntry(normalized, null, null, "fulfilled", hydrated.value);
|
|
201
246
|
this.entries.set(storeKey, entry);
|
|
202
247
|
this.notifyEntryChange(entry);
|
|
203
248
|
}
|
|
204
249
|
}
|
|
205
250
|
snapshot() {
|
|
251
|
+
return this.snapshotKeys(this.entries.keys());
|
|
252
|
+
}
|
|
253
|
+
snapshotKeys(canonicalKeys) {
|
|
206
254
|
const entries = [];
|
|
207
|
-
for (const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
255
|
+
for (const key of canonicalKeys) {
|
|
256
|
+
const entry = this.entries.get(key);
|
|
257
|
+
if (entry !== void 0 && entryHasValue(entry)) entries.push({
|
|
258
|
+
key: entry.key,
|
|
259
|
+
value: entry.value
|
|
260
|
+
});
|
|
261
|
+
}
|
|
211
262
|
return entries;
|
|
212
263
|
}
|
|
213
264
|
inspectDataEntries() {
|
|
@@ -247,8 +298,12 @@ var DefaultDataStore = class {
|
|
|
247
298
|
for (const entry of this.entries.values()) if (canonicalKeyStartsWith(entry.canonicalKey, prefixCanonical)) entries.push(entry);
|
|
248
299
|
this.invalidateEntries(entries);
|
|
249
300
|
}
|
|
250
|
-
|
|
301
|
+
ensureData(resource, ...args) {
|
|
302
|
+
return this.ensureDataUntil(resource, args, void 0);
|
|
303
|
+
}
|
|
304
|
+
async ensureDataUntil(resource, args, until) {
|
|
251
305
|
for (;;) {
|
|
306
|
+
if (until?.aborted === true) throw until.reason;
|
|
252
307
|
if (this.disposed) throw new Error("ensureData() requires a live data store; this store was disposed.");
|
|
253
308
|
const entry = this.entryFor(resource, args, true);
|
|
254
309
|
this.clearInactiveTimer(entry);
|
|
@@ -258,16 +313,24 @@ var DefaultDataStore = class {
|
|
|
258
313
|
return entry.value;
|
|
259
314
|
}
|
|
260
315
|
if (entry.status === "rejected") throwDataResourceError(entry);
|
|
261
|
-
|
|
316
|
+
const retainer = {};
|
|
317
|
+
(entry.retainers ??= /* @__PURE__ */ new Set()).add(retainer);
|
|
262
318
|
try {
|
|
263
|
-
|
|
264
|
-
|
|
319
|
+
this.recordWatchSource(entry, resource, args);
|
|
320
|
+
let settled;
|
|
321
|
+
if (entry.pending !== null) settled = entry.pending.promise;
|
|
322
|
+
else if (this.waitsOnWatch(resource)) settled = this.beginWatchPending(entry).promise;
|
|
323
|
+
else settled = this.startLoad(entry, resource, args, {
|
|
265
324
|
lane: this.host.getLane(),
|
|
266
325
|
refresh: false
|
|
267
326
|
});
|
|
327
|
+
await (until === void 0 ? settled : untilAborted(settled, until));
|
|
268
328
|
} finally {
|
|
269
|
-
entry.
|
|
270
|
-
if (this.entries.get(entry.
|
|
329
|
+
entry.retainers?.delete(retainer);
|
|
330
|
+
if (this.entries.get(entry.canonicalKey) === entry) {
|
|
331
|
+
this.retainPreload(entry);
|
|
332
|
+
this.scheduleWatchReconcile(entry);
|
|
333
|
+
}
|
|
271
334
|
}
|
|
272
335
|
}
|
|
273
336
|
}
|
|
@@ -287,14 +350,19 @@ var DefaultDataStore = class {
|
|
|
287
350
|
const entry = this.entryFor(resource, args, true);
|
|
288
351
|
this.clearInactiveTimer(entry);
|
|
289
352
|
this.clearPreloadTimer(entry);
|
|
290
|
-
if (reads !== void 0
|
|
353
|
+
if (reads !== void 0) (entry.retainers ??= /* @__PURE__ */ new Set()).add(reads);
|
|
354
|
+
if (reads !== void 0 && !reads.has(entry.canonicalKey)) reads.set(entry.canonicalKey, void 0);
|
|
355
|
+
this.recordWatchSource(entry, resource, args);
|
|
291
356
|
this.revalidateIfStale(entry, resource, args);
|
|
292
|
-
if (entry.status === "pending" && entry.pending === null)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
357
|
+
if (entry.status === "pending" && entry.pending === null) {
|
|
358
|
+
if (this.waitsOnWatch(resource)) this.beginWatchPending(entry);
|
|
359
|
+
else this.startLoad(entry, resource, args, {
|
|
360
|
+
lane: this.host.getLane(),
|
|
361
|
+
refresh: false
|
|
362
|
+
});
|
|
363
|
+
}
|
|
296
364
|
const value = this.readCurrentValue(entry);
|
|
297
|
-
if (reads !== void 0 && reads.get(entry.
|
|
365
|
+
if (reads !== void 0 && reads.get(entry.canonicalKey) === void 0) reads.set(entry.canonicalKey, { value });
|
|
298
366
|
return value;
|
|
299
367
|
}
|
|
300
368
|
refreshData(resource, ...args) {
|
|
@@ -328,11 +396,15 @@ var DefaultDataStore = class {
|
|
|
328
396
|
entryFor(resource, args, create) {
|
|
329
397
|
const normalized = normalizeKey(resource.key(...args));
|
|
330
398
|
const fingerprint = null;
|
|
331
|
-
const key =
|
|
399
|
+
const key = normalized.canonical;
|
|
332
400
|
const current = this.entries.get(key);
|
|
333
|
-
if (current !== void 0)
|
|
401
|
+
if (current !== void 0) {
|
|
402
|
+
if (resource.inactiveRetentionMs !== void 0) current.inactiveRetentionMs = resource.inactiveRetentionMs;
|
|
403
|
+
return current;
|
|
404
|
+
}
|
|
334
405
|
if (!create) return null;
|
|
335
|
-
const entry = this.createEntry(normalized,
|
|
406
|
+
const entry = this.createEntry(normalized, resource, fingerprint, "pending", void 0);
|
|
407
|
+
entry.inactiveRetentionMs = resource.inactiveRetentionMs;
|
|
336
408
|
if (this.disposed) return entry;
|
|
337
409
|
this.entries.set(key, entry);
|
|
338
410
|
this.notifyEntryChange(entry);
|
|
@@ -347,15 +419,16 @@ var DefaultDataStore = class {
|
|
|
347
419
|
}
|
|
348
420
|
entryForKey(key) {
|
|
349
421
|
const normalized = normalizeKey(key);
|
|
350
|
-
return this.entries.get(
|
|
422
|
+
return this.entries.get(normalized.canonical) ?? null;
|
|
351
423
|
}
|
|
352
|
-
createEntry(normalized,
|
|
424
|
+
createEntry(normalized, resource, fingerprint, status, value) {
|
|
353
425
|
return {
|
|
354
426
|
canonicalKey: normalized.canonical,
|
|
355
|
-
|
|
427
|
+
retainers: null,
|
|
356
428
|
error: void 0,
|
|
357
429
|
fingerprint,
|
|
358
430
|
invalidationVersion: 0,
|
|
431
|
+
inactiveRetentionMs: void 0,
|
|
359
432
|
inactiveTimer: null,
|
|
360
433
|
key: normalized.key,
|
|
361
434
|
lane: null,
|
|
@@ -366,13 +439,190 @@ var DefaultDataStore = class {
|
|
|
366
439
|
resource,
|
|
367
440
|
stale: false,
|
|
368
441
|
status,
|
|
369
|
-
storeKey,
|
|
370
442
|
subscribers: /* @__PURE__ */ new Set(),
|
|
371
443
|
value,
|
|
372
444
|
valueController: null,
|
|
373
|
-
valueErrors: /* @__PURE__ */ new WeakSet()
|
|
445
|
+
valueErrors: /* @__PURE__ */ new WeakSet(),
|
|
446
|
+
watchController: null,
|
|
447
|
+
watchSource: null
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
recordWatchSource(entry, resource, args) {
|
|
451
|
+
if (resource.watch === void 0 || entry.watchSource !== null) return;
|
|
452
|
+
entry.watchSource = {
|
|
453
|
+
args,
|
|
454
|
+
resource
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
waitsOnWatch(resource) {
|
|
458
|
+
return resource.load === void 0 && resource.watch !== void 0 && this.host.watchSources === true;
|
|
459
|
+
}
|
|
460
|
+
beginWatchPending(entry) {
|
|
461
|
+
if (entry.pending !== null) return entry.pending;
|
|
462
|
+
const pending = createPendingLoad(new AbortController());
|
|
463
|
+
pending.watch = true;
|
|
464
|
+
entry.pending = pending;
|
|
465
|
+
entry.status = "pending";
|
|
466
|
+
this.notifyEntryChange(entry);
|
|
467
|
+
this.scheduleWatchReconcile(entry);
|
|
468
|
+
return pending;
|
|
469
|
+
}
|
|
470
|
+
dependentHandle(signal) {
|
|
471
|
+
const retain = (entry) => {
|
|
472
|
+
if (signal.aborted || entry.retainers?.has(signal)) return;
|
|
473
|
+
(entry.retainers ??= /* @__PURE__ */ new Set()).add(signal);
|
|
474
|
+
this.clearInactiveTimer(entry);
|
|
475
|
+
signal.addEventListener("abort", () => this.releaseRetainer(entry, signal), { once: true });
|
|
476
|
+
};
|
|
477
|
+
return {
|
|
478
|
+
ensureData: (resource, ...args) => {
|
|
479
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
480
|
+
if (!this.disposed) {
|
|
481
|
+
const entry = this.entryFor(resource, args, true);
|
|
482
|
+
this.recordWatchSource(entry, resource, args);
|
|
483
|
+
retain(entry);
|
|
484
|
+
this.scheduleWatchReconcile(entry);
|
|
485
|
+
}
|
|
486
|
+
return this.ensureDataUntil(resource, args, signal);
|
|
487
|
+
},
|
|
488
|
+
hydrate: (entries) => this.hydrate(entries),
|
|
489
|
+
invalidateData: (resource, ...args) => this.invalidateData(resource, ...args),
|
|
490
|
+
invalidateDataError: (error) => this.invalidateDataError(error),
|
|
491
|
+
invalidateDataKey: (key) => this.invalidateDataKey(key),
|
|
492
|
+
invalidateDataPrefix: (prefix) => this.invalidateDataPrefix(prefix),
|
|
493
|
+
preloadData: (resource, ...args) => this.preloadData(resource, ...args),
|
|
494
|
+
refreshData: (resource, ...args) => this.refreshData(resource, ...args),
|
|
495
|
+
run: (callback) => this.run(callback)
|
|
374
496
|
};
|
|
375
497
|
}
|
|
498
|
+
keepEqualValue(entry, stale) {
|
|
499
|
+
entry.error = void 0;
|
|
500
|
+
entry.pending = null;
|
|
501
|
+
entry.refreshError = void 0;
|
|
502
|
+
entry.refreshFailed = false;
|
|
503
|
+
entry.stale = stale;
|
|
504
|
+
entry.status = "fulfilled";
|
|
505
|
+
this.notifyEntryChange(entry);
|
|
506
|
+
this.scheduleInactiveCleanup(entry);
|
|
507
|
+
}
|
|
508
|
+
scheduleWatchReconcile(entry) {
|
|
509
|
+
if (entry.watchSource === null && entry.watchController === null) return;
|
|
510
|
+
if (this.pendingWatchReconciles !== null) {
|
|
511
|
+
this.pendingWatchReconciles.add(entry);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const entries = /* @__PURE__ */ new Set([entry]);
|
|
515
|
+
this.pendingWatchReconciles = entries;
|
|
516
|
+
queueMicrotask(() => {
|
|
517
|
+
this.pendingWatchReconciles = null;
|
|
518
|
+
for (const pending of entries) this.reconcileWatch(pending);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
wantsWatch(entry) {
|
|
522
|
+
const source = entry.watchSource;
|
|
523
|
+
if (source === null || this.disposed || this.host.watchSources !== true || this.entries.get(entry.canonicalKey) !== entry) return false;
|
|
524
|
+
if (entry.subscribers.size > 0) return true;
|
|
525
|
+
return source.resource.load === void 0 && isHeld(entry);
|
|
526
|
+
}
|
|
527
|
+
reconcileWatch(entry) {
|
|
528
|
+
const wanted = this.wantsWatch(entry);
|
|
529
|
+
if (wanted && entry.watchController === null) this.startWatch(entry);
|
|
530
|
+
else if (!wanted && entry.watchController !== null) this.stopWatch(entry, "released");
|
|
531
|
+
if (!wanted && entry.pending?.watch === true && !isHeld(entry)) this.evictEntry(entry, "evicted");
|
|
532
|
+
}
|
|
533
|
+
holdDataRead(reads, canonicalKey) {
|
|
534
|
+
if (!reads.has(canonicalKey)) reads.set(canonicalKey, void 0);
|
|
535
|
+
const entry = this.entries.get(canonicalKey);
|
|
536
|
+
if (entry !== void 0) (entry.retainers ??= /* @__PURE__ */ new Set()).add(reads);
|
|
537
|
+
}
|
|
538
|
+
releaseDataReads(reads) {
|
|
539
|
+
for (const key of reads.keys()) {
|
|
540
|
+
const entry = this.entries.get(key);
|
|
541
|
+
if (entry !== void 0) this.releaseRetainer(entry, reads);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
releaseRetainer(entry, owner) {
|
|
545
|
+
if (!entry.retainers?.delete(owner) || this.entries.get(entry.canonicalKey) !== entry) return;
|
|
546
|
+
this.scheduleInactiveCleanup(entry);
|
|
547
|
+
this.scheduleWatchReconcile(entry);
|
|
548
|
+
}
|
|
549
|
+
startWatch(entry) {
|
|
550
|
+
const source = entry.watchSource;
|
|
551
|
+
const watch = source?.resource.watch;
|
|
552
|
+
if (source === null || watch === void 0) return;
|
|
553
|
+
const controller = new AbortController();
|
|
554
|
+
entry.watchController = controller;
|
|
555
|
+
this.notifyEntryChange(entry);
|
|
556
|
+
const context = this.createWatchContext(entry, source, controller);
|
|
557
|
+
try {
|
|
558
|
+
watch(...source.args, context);
|
|
559
|
+
} catch (error) {
|
|
560
|
+
context.fail(error);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
stopWatch(entry, reason) {
|
|
564
|
+
const controller = entry.watchController;
|
|
565
|
+
if (controller === null) return;
|
|
566
|
+
entry.watchController = null;
|
|
567
|
+
if (reason === "released" && entryHasValue(entry)) entry.stale = true;
|
|
568
|
+
this.notifyEntryChange(entry);
|
|
569
|
+
controller.abort(reason);
|
|
570
|
+
}
|
|
571
|
+
createWatchContext(entry, source, controller) {
|
|
572
|
+
const live = () => !this.disposed && !controller.signal.aborted && this.entries.get(entry.canonicalKey) === entry;
|
|
573
|
+
return {
|
|
574
|
+
data: this.dependentHandle(controller.signal),
|
|
575
|
+
signal: controller.signal,
|
|
576
|
+
publish: (value) => {
|
|
577
|
+
if (!live()) return;
|
|
578
|
+
const equals = source.resource.equals ?? Object.is;
|
|
579
|
+
if (entryHasValue(entry) && equals(entry.value, value)) {
|
|
580
|
+
const pending = entry.pending;
|
|
581
|
+
entry.invalidationVersion = 0;
|
|
582
|
+
entry.lane = null;
|
|
583
|
+
this.keepEqualValue(entry, false);
|
|
584
|
+
pending?.resolve(abortedRefreshResult(entry, "superseded"));
|
|
585
|
+
pending?.controller.abort("superseded");
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
this.hydrateEntry(entry, entry.key, value);
|
|
589
|
+
this.scheduleWatchReconcile(entry);
|
|
590
|
+
},
|
|
591
|
+
fail: (error) => {
|
|
592
|
+
if (!live()) return;
|
|
593
|
+
this.failWatchedEntry(entry, error);
|
|
594
|
+
},
|
|
595
|
+
refresh: () => {
|
|
596
|
+
if (live()) return this.refreshData(source.resource, ...source.args);
|
|
597
|
+
const reason = this.disposed ? "store-disposed" : controller.signal.reason === "released" ? "released" : "evicted";
|
|
598
|
+
return Promise.resolve(abortedRefreshResult(entry, reason));
|
|
599
|
+
},
|
|
600
|
+
invalidate: () => {
|
|
601
|
+
if (!live()) return;
|
|
602
|
+
this.invalidateEntry(entry, this.host.getLane());
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
failWatchedEntry(entry, error) {
|
|
607
|
+
if (entryHasValue(entry)) {
|
|
608
|
+
entry.refreshError = error;
|
|
609
|
+
entry.refreshFailed = true;
|
|
610
|
+
entry.stale = true;
|
|
611
|
+
this.publish(entry);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const pending = entry.pending;
|
|
615
|
+
entry.pending = null;
|
|
616
|
+
entry.error = error;
|
|
617
|
+
entry.status = "rejected";
|
|
618
|
+
markDataResourceError(error, entry.key);
|
|
619
|
+
pending?.resolve({
|
|
620
|
+
error,
|
|
621
|
+
status: "rejected"
|
|
622
|
+
});
|
|
623
|
+
this.publish(entry);
|
|
624
|
+
pending?.controller.abort(error);
|
|
625
|
+
}
|
|
376
626
|
hydrateEntry(entry, key, value) {
|
|
377
627
|
this.clearInactiveTimer(entry);
|
|
378
628
|
const valueController = entry.valueController;
|
|
@@ -394,9 +644,6 @@ var DefaultDataStore = class {
|
|
|
394
644
|
pending?.controller.abort("superseded");
|
|
395
645
|
valueController?.abort("superseded");
|
|
396
646
|
}
|
|
397
|
-
storeKey(canonicalKey) {
|
|
398
|
-
return this.partitionKey === "" ? canonicalKey : `${this.partitionKey}:${canonicalKey}`;
|
|
399
|
-
}
|
|
400
647
|
startLoad(entry, resource, args, options) {
|
|
401
648
|
const hadValue = entryHasValue(entry);
|
|
402
649
|
const load = resource.load;
|
|
@@ -434,6 +681,23 @@ var DefaultDataStore = class {
|
|
|
434
681
|
};
|
|
435
682
|
const fulfill = (value) => {
|
|
436
683
|
if (entry.pending !== pending || controller.signal.aborted) return settleAborted();
|
|
684
|
+
const equals = resource.equals ?? Object.is;
|
|
685
|
+
let equal;
|
|
686
|
+
try {
|
|
687
|
+
equal = entryHasValue(entry) && equals(entry.value, value);
|
|
688
|
+
} catch (error) {
|
|
689
|
+
return reject(error);
|
|
690
|
+
}
|
|
691
|
+
if (equal) {
|
|
692
|
+
this.keepEqualValue(entry, entry.invalidationVersion !== invalidationVersion);
|
|
693
|
+
const result = {
|
|
694
|
+
status: "fulfilled",
|
|
695
|
+
value: entry.value
|
|
696
|
+
};
|
|
697
|
+
pending.resolve(result);
|
|
698
|
+
controller.abort("superseded");
|
|
699
|
+
return result;
|
|
700
|
+
}
|
|
437
701
|
const superseded = entry.valueController;
|
|
438
702
|
entry.valueController = controller;
|
|
439
703
|
entry.valueErrors = valueErrors;
|
|
@@ -495,7 +759,10 @@ var DefaultDataStore = class {
|
|
|
495
759
|
return pending.promise;
|
|
496
760
|
}
|
|
497
761
|
createLoadContext(entry, controller, valueErrors) {
|
|
498
|
-
const context = {
|
|
762
|
+
const context = {
|
|
763
|
+
data: this.dependentHandle(controller.signal),
|
|
764
|
+
signal: controller.signal
|
|
765
|
+
};
|
|
499
766
|
defineLoadContextCapabilities(context, {
|
|
500
767
|
key: entry.key,
|
|
501
768
|
attributeError: (error) => {
|
|
@@ -505,7 +772,7 @@ var DefaultDataStore = class {
|
|
|
505
772
|
},
|
|
506
773
|
hydrate: (entries) => {
|
|
507
774
|
if (this.disposed || controller.signal.aborted) return;
|
|
508
|
-
const foreign = entries.filter((hydrated) =>
|
|
775
|
+
const foreign = entries.filter((hydrated) => normalizeKey(hydrated.key).canonical !== entry.canonicalKey);
|
|
509
776
|
for (const hydrated of foreign) {
|
|
510
777
|
if (controller.signal.aborted) return;
|
|
511
778
|
this.hydrate([hydrated]);
|
|
@@ -530,13 +797,14 @@ var DefaultDataStore = class {
|
|
|
530
797
|
pending?.resolve(abortedRefreshResult(entry, reason));
|
|
531
798
|
pending?.controller.abort(reason);
|
|
532
799
|
valueController?.abort(reason);
|
|
800
|
+
this.stopWatch(entry, reason);
|
|
533
801
|
}
|
|
534
802
|
retainPreload(entry) {
|
|
535
803
|
this.clearPreloadTimer(entry);
|
|
536
804
|
if (this.disposed || !Number.isFinite(this.preloadRetentionMs)) return;
|
|
537
805
|
entry.preloadTimer = scheduleStoreTimer(() => {
|
|
538
806
|
entry.preloadTimer = null;
|
|
539
|
-
if (entry
|
|
807
|
+
if (!isHeld(entry) && entry.pending !== null && !entryHasValue(entry)) {
|
|
540
808
|
this.evictEntry(entry, "evicted");
|
|
541
809
|
return;
|
|
542
810
|
}
|
|
@@ -544,19 +812,20 @@ var DefaultDataStore = class {
|
|
|
544
812
|
}, Math.max(0, this.preloadRetentionMs));
|
|
545
813
|
}
|
|
546
814
|
scheduleInactiveCleanup(entry) {
|
|
547
|
-
|
|
815
|
+
const retention = entry.inactiveRetentionMs ?? this.inactiveRetentionMs;
|
|
816
|
+
if (this.disposed || isHeld(entry) || entry.pending !== null || entry.preloadTimer !== null || !Number.isFinite(retention)) return;
|
|
548
817
|
this.clearInactiveTimer(entry);
|
|
549
818
|
entry.inactiveTimer = scheduleStoreTimer(() => {
|
|
550
819
|
entry.inactiveTimer = null;
|
|
551
|
-
if (entry
|
|
820
|
+
if (isHeld(entry) || entry.pending !== null || entry.preloadTimer !== null) return;
|
|
552
821
|
this.evictEntry(entry, "evicted");
|
|
553
|
-
}, Math.max(0,
|
|
822
|
+
}, Math.max(0, retention));
|
|
554
823
|
}
|
|
555
824
|
evictEntry(entry, reason) {
|
|
556
|
-
if (this.entries.get(entry.
|
|
825
|
+
if (this.entries.get(entry.canonicalKey) !== entry) return;
|
|
557
826
|
this.clearInactiveTimer(entry);
|
|
558
827
|
this.clearPreloadTimer(entry);
|
|
559
|
-
this.entries.delete(entry.
|
|
828
|
+
this.entries.delete(entry.canonicalKey);
|
|
560
829
|
this.abortEntryGenerations(entry, reason);
|
|
561
830
|
this.host.onEntryEvict?.(this.snapshotEntry(entry));
|
|
562
831
|
}
|
|
@@ -585,7 +854,8 @@ var DefaultDataStore = class {
|
|
|
585
854
|
stale: entry.stale,
|
|
586
855
|
status: entry.status,
|
|
587
856
|
subscriberCount: entry.subscribers.size,
|
|
588
|
-
value: hasValue ? entry.value : void 0
|
|
857
|
+
value: hasValue ? entry.value : void 0,
|
|
858
|
+
...entry.watchController === null ? {} : { watching: true }
|
|
589
859
|
};
|
|
590
860
|
}
|
|
591
861
|
readCurrentValue(entry) {
|
|
@@ -633,6 +903,9 @@ function canonicalKeyStartsWith(key, prefix) {
|
|
|
633
903
|
const arrayPrefix = prefix.slice(0, -1);
|
|
634
904
|
return key.startsWith(arrayPrefix) && key[arrayPrefix.length] === ",";
|
|
635
905
|
}
|
|
906
|
+
function isHeld(entry) {
|
|
907
|
+
return entry.subscribers.size > 0 || (entry.retainers?.size ?? 0) > 0;
|
|
908
|
+
}
|
|
636
909
|
function entryHasValue(entry) {
|
|
637
910
|
return entry.status === "fulfilled" || entry.status === "refreshing";
|
|
638
911
|
}
|
|
@@ -707,6 +980,20 @@ function encodeValue(value, path) {
|
|
|
707
980
|
function isThenable(value) {
|
|
708
981
|
return (typeof value === "object" || typeof value === "function") && value !== null && "then" in value && typeof value.then === "function";
|
|
709
982
|
}
|
|
983
|
+
function untilAborted(promise, signal) {
|
|
984
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
985
|
+
return new Promise((resolve, reject) => {
|
|
986
|
+
const abort = () => reject(signal.reason);
|
|
987
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
988
|
+
promise.then((value) => {
|
|
989
|
+
signal.removeEventListener("abort", abort);
|
|
990
|
+
resolve(value);
|
|
991
|
+
}, (error) => {
|
|
992
|
+
signal.removeEventListener("abort", abort);
|
|
993
|
+
reject(error);
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
}
|
|
710
997
|
function createPendingLoad(controller) {
|
|
711
998
|
let resolve = () => void 0;
|
|
712
999
|
return {
|
|
@@ -779,6 +1066,6 @@ function setTransitionHandler(handler) {
|
|
|
779
1066
|
return previous;
|
|
780
1067
|
}
|
|
781
1068
|
//#endregion
|
|
782
|
-
export {
|
|
1069
|
+
export { resolveCurrentDataStore as _, createDataStore as a, createContext as b, dataResource as c, readDataStore as d, runWithDataStore as f, markDataResourceError as g, loadContextCapabilities as h, attachDataStore as i, isDataStoreController as l, defineLoadContextCapabilities as m, setTransitionHandler as n, createRendererDataStore as o, dataResourceKeysForError as p, transition as r, currentDataStore as s, runTransitionScope as t, normalizeDataResourceKey as u, setCurrentDataStore as v, isContext as x, FigContextSymbol as y };
|
|
783
1070
|
|
|
784
|
-
//# sourceMappingURL=transition-
|
|
1071
|
+
//# sourceMappingURL=transition-BFLGYE4q.js.map
|