@vertz/ui 0.2.0 → 0.2.2
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 +339 -857
- package/dist/css/public.d.ts +24 -27
- package/dist/css/public.js +5 -1
- package/dist/form/public.d.ts +94 -38
- package/dist/form/public.js +5 -3
- package/dist/index.d.ts +754 -167
- package/dist/index.js +606 -84
- package/dist/internals.d.ts +192 -23
- package/dist/internals.js +151 -102
- package/dist/jsx-runtime/index.d.ts +44 -17
- package/dist/jsx-runtime/index.js +26 -7
- package/dist/query/public.d.ts +73 -7
- package/dist/query/public.js +12 -4
- package/dist/router/public.d.ts +199 -26
- package/dist/router/public.js +22 -7
- package/dist/shared/chunk-0xcmwgdb.js +288 -0
- package/dist/shared/{chunk-j8vzvne3.js → chunk-9e92w0wt.js} +4 -1
- package/dist/shared/chunk-g4rch80a.js +33 -0
- package/dist/shared/chunk-hh0dhmb4.js +528 -0
- package/dist/shared/{chunk-pgymxpn1.js → chunk-hrd0mft1.js} +136 -34
- package/dist/shared/chunk-jrtrk5z4.js +125 -0
- package/dist/shared/chunk-ka5ked7n.js +188 -0
- package/dist/shared/chunk-n91rwj2r.js +483 -0
- package/dist/shared/chunk-prj7nm08.js +67 -0
- package/dist/shared/chunk-q6cpe5k7.js +230 -0
- package/dist/shared/{chunk-f1ynwam4.js → chunk-qacth5ah.js} +162 -36
- package/dist/shared/chunk-ryb49346.js +374 -0
- package/dist/shared/chunk-v3yyf79g.js +48 -0
- package/dist/test/index.d.ts +67 -6
- package/dist/test/index.js +4 -3
- package/package.json +14 -9
- package/dist/shared/chunk-bp3v6s9j.js +0 -62
- package/dist/shared/chunk-d8h2eh8d.js +0 -141
- package/dist/shared/chunk-tsdpgmks.js +0 -98
- package/dist/shared/chunk-xd9d7q5p.js +0 -115
- package/dist/shared/chunk-zbbvx05f.js +0 -202
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isNavPrefetchActive
|
|
3
|
+
} from "./chunk-jrtrk5z4.js";
|
|
4
|
+
import {
|
|
5
|
+
getAdapter,
|
|
6
|
+
isRenderNode
|
|
7
|
+
} from "./chunk-g4rch80a.js";
|
|
8
|
+
import {
|
|
9
|
+
_tryOnCleanup,
|
|
10
|
+
computed,
|
|
11
|
+
domEffect,
|
|
12
|
+
lifecycleEffect,
|
|
13
|
+
popScope,
|
|
14
|
+
pushScope,
|
|
15
|
+
runCleanups,
|
|
16
|
+
setReadValueCallback,
|
|
17
|
+
signal,
|
|
18
|
+
untrack
|
|
19
|
+
} from "./chunk-hrd0mft1.js";
|
|
20
|
+
|
|
21
|
+
// src/query/cache.ts
|
|
22
|
+
class MemoryCache {
|
|
23
|
+
_store = new Map;
|
|
24
|
+
get(key) {
|
|
25
|
+
return this._store.get(key);
|
|
26
|
+
}
|
|
27
|
+
set(key, value) {
|
|
28
|
+
this._store.set(key, value);
|
|
29
|
+
}
|
|
30
|
+
delete(key) {
|
|
31
|
+
this._store.delete(key);
|
|
32
|
+
}
|
|
33
|
+
clear() {
|
|
34
|
+
this._store.clear();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/query/key-derivation.ts
|
|
39
|
+
function deriveKey(thunk) {
|
|
40
|
+
return `__q:${hashString(thunk.toString())}`;
|
|
41
|
+
}
|
|
42
|
+
function hashString(str) {
|
|
43
|
+
let hash = 5381;
|
|
44
|
+
for (let i = 0;i < str.length; i++) {
|
|
45
|
+
hash = hash * 33 ^ str.charCodeAt(i);
|
|
46
|
+
}
|
|
47
|
+
return (hash >>> 0).toString(36);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/query/query.ts
|
|
51
|
+
import { isQueryDescriptor } from "@vertz/fetch";
|
|
52
|
+
|
|
53
|
+
// src/query/ssr-hydration.ts
|
|
54
|
+
function hydrateQueryFromSSR(key, resolve, options) {
|
|
55
|
+
const ssrData = globalThis.__VERTZ_SSR_DATA__;
|
|
56
|
+
if (!ssrData)
|
|
57
|
+
return null;
|
|
58
|
+
const persistent = options?.persistent ?? false;
|
|
59
|
+
const existing = ssrData.find((entry) => entry.key === key);
|
|
60
|
+
if (existing) {
|
|
61
|
+
resolve(existing.data);
|
|
62
|
+
if (!persistent)
|
|
63
|
+
return () => {};
|
|
64
|
+
}
|
|
65
|
+
const handler = (event) => {
|
|
66
|
+
const detail = event.detail;
|
|
67
|
+
if (detail.key === key) {
|
|
68
|
+
resolve(detail.data);
|
|
69
|
+
if (!persistent) {
|
|
70
|
+
document.removeEventListener("vertz:ssr-data", handler);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
document.addEventListener("vertz:ssr-data", handler);
|
|
75
|
+
return () => {
|
|
76
|
+
document.removeEventListener("vertz:ssr-data", handler);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/query/query.ts
|
|
81
|
+
function isSSR() {
|
|
82
|
+
const check = typeof globalThis !== "undefined" && globalThis.__VERTZ_IS_SSR__;
|
|
83
|
+
return typeof check === "function" ? check() : false;
|
|
84
|
+
}
|
|
85
|
+
function getGlobalSSRTimeout() {
|
|
86
|
+
const g = globalThis;
|
|
87
|
+
const getter = typeof globalThis !== "undefined" && g.__VERTZ_GET_GLOBAL_SSR_TIMEOUT__;
|
|
88
|
+
return typeof getter === "function" ? getter() : undefined;
|
|
89
|
+
}
|
|
90
|
+
var defaultCache = new MemoryCache;
|
|
91
|
+
var inflight = new Map;
|
|
92
|
+
function clearDefaultQueryCache() {
|
|
93
|
+
defaultCache.clear();
|
|
94
|
+
inflight.clear();
|
|
95
|
+
}
|
|
96
|
+
globalThis.__VERTZ_CLEAR_QUERY_CACHE__ = clearDefaultQueryCache;
|
|
97
|
+
function query(source, options = {}) {
|
|
98
|
+
if (isQueryDescriptor(source)) {
|
|
99
|
+
return query(async () => {
|
|
100
|
+
const result = await source._fetch();
|
|
101
|
+
if (!result.ok)
|
|
102
|
+
throw result.error;
|
|
103
|
+
return result.data;
|
|
104
|
+
}, { ...options, key: source._key });
|
|
105
|
+
}
|
|
106
|
+
const thunk = source;
|
|
107
|
+
const {
|
|
108
|
+
initialData,
|
|
109
|
+
debounce: debounceMs,
|
|
110
|
+
enabled = true,
|
|
111
|
+
key: customKey,
|
|
112
|
+
cache = defaultCache
|
|
113
|
+
} = options;
|
|
114
|
+
const baseKey = deriveKey(thunk);
|
|
115
|
+
const depHashSignal = signal("");
|
|
116
|
+
const cacheKeyComputed = computed(() => {
|
|
117
|
+
const dh = depHashSignal.value;
|
|
118
|
+
return customKey ?? (dh ? `${baseKey}:${dh}` : `${baseKey}:init`);
|
|
119
|
+
});
|
|
120
|
+
function getCacheKey() {
|
|
121
|
+
return cacheKeyComputed.value;
|
|
122
|
+
}
|
|
123
|
+
function callThunkWithCapture() {
|
|
124
|
+
const captured = [];
|
|
125
|
+
const prevCb = setReadValueCallback((v) => captured.push(v));
|
|
126
|
+
let promise;
|
|
127
|
+
try {
|
|
128
|
+
promise = thunk();
|
|
129
|
+
} finally {
|
|
130
|
+
setReadValueCallback(prevCb);
|
|
131
|
+
}
|
|
132
|
+
const serialized = captured.map((v) => JSON.stringify(v)).join("|");
|
|
133
|
+
untrack(() => {
|
|
134
|
+
depHashSignal.value = hashString(serialized);
|
|
135
|
+
});
|
|
136
|
+
return promise;
|
|
137
|
+
}
|
|
138
|
+
const data = signal(initialData);
|
|
139
|
+
const loading = signal(initialData === undefined && enabled);
|
|
140
|
+
const revalidating = signal(false);
|
|
141
|
+
const error = signal(undefined);
|
|
142
|
+
if (initialData !== undefined) {
|
|
143
|
+
cache.set(getCacheKey(), initialData);
|
|
144
|
+
}
|
|
145
|
+
const ssrTimeout = options.ssrTimeout ?? getGlobalSSRTimeout() ?? 300;
|
|
146
|
+
if (isSSR() && enabled && ssrTimeout !== 0 && initialData === undefined) {
|
|
147
|
+
const promise = callThunkWithCapture();
|
|
148
|
+
const key = untrack(() => getCacheKey());
|
|
149
|
+
const cached = cache.get(key);
|
|
150
|
+
if (cached !== undefined) {
|
|
151
|
+
promise.catch(() => {});
|
|
152
|
+
data.value = cached;
|
|
153
|
+
loading.value = false;
|
|
154
|
+
} else {
|
|
155
|
+
promise.catch(() => {});
|
|
156
|
+
const register = globalThis.__VERTZ_SSR_REGISTER_QUERY__;
|
|
157
|
+
if (typeof register === "function") {
|
|
158
|
+
register({
|
|
159
|
+
promise,
|
|
160
|
+
timeout: ssrTimeout,
|
|
161
|
+
resolve: (result) => {
|
|
162
|
+
data.value = result;
|
|
163
|
+
loading.value = false;
|
|
164
|
+
cache.set(key, result);
|
|
165
|
+
},
|
|
166
|
+
key
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
let ssrHydrationCleanup = null;
|
|
172
|
+
let ssrHydrated = false;
|
|
173
|
+
let navPrefetchDeferred = false;
|
|
174
|
+
if (!isSSR() && enabled && initialData === undefined) {
|
|
175
|
+
const hydrationKey = customKey ?? baseKey;
|
|
176
|
+
const isNavigation = isNavPrefetchActive();
|
|
177
|
+
ssrHydrationCleanup = hydrateQueryFromSSR(hydrationKey, (result) => {
|
|
178
|
+
data.value = result;
|
|
179
|
+
loading.value = false;
|
|
180
|
+
cache.set(hydrationKey, result);
|
|
181
|
+
ssrHydrated = true;
|
|
182
|
+
}, { persistent: isNavigation });
|
|
183
|
+
if (!ssrHydrated && ssrHydrationCleanup !== null && isNavPrefetchActive()) {
|
|
184
|
+
if (customKey) {
|
|
185
|
+
const cached = cache.get(customKey);
|
|
186
|
+
if (cached !== undefined) {
|
|
187
|
+
data.value = cached;
|
|
188
|
+
loading.value = false;
|
|
189
|
+
ssrHydrated = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!ssrHydrated && ssrHydrationCleanup !== null && isNavPrefetchActive()) {
|
|
194
|
+
navPrefetchDeferred = true;
|
|
195
|
+
const doneHandler = () => {
|
|
196
|
+
document.removeEventListener("vertz:nav-prefetch-done", doneHandler);
|
|
197
|
+
if (data.peek() === undefined && !ssrHydrated) {
|
|
198
|
+
refetchTrigger.value = refetchTrigger.peek() + 1;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
document.addEventListener("vertz:nav-prefetch-done", doneHandler);
|
|
202
|
+
const prevCleanup = ssrHydrationCleanup;
|
|
203
|
+
ssrHydrationCleanup = () => {
|
|
204
|
+
prevCleanup?.();
|
|
205
|
+
document.removeEventListener("vertz:nav-prefetch-done", doneHandler);
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
let fetchId = 0;
|
|
210
|
+
let debounceTimer;
|
|
211
|
+
let intervalTimer;
|
|
212
|
+
const refetchIntervalOption = options.refetchInterval;
|
|
213
|
+
const hasInterval = typeof refetchIntervalOption === "function" || typeof refetchIntervalOption === "number" && refetchIntervalOption > 0;
|
|
214
|
+
let intervalIteration = 0;
|
|
215
|
+
const inflightKeys = new Set;
|
|
216
|
+
const refetchTrigger = signal(0);
|
|
217
|
+
let intervalPaused = false;
|
|
218
|
+
function scheduleInterval() {
|
|
219
|
+
if (!hasInterval || isSSR() || intervalPaused)
|
|
220
|
+
return;
|
|
221
|
+
let ms;
|
|
222
|
+
if (typeof refetchIntervalOption === "function") {
|
|
223
|
+
ms = refetchIntervalOption(data.peek(), intervalIteration);
|
|
224
|
+
} else {
|
|
225
|
+
ms = refetchIntervalOption;
|
|
226
|
+
}
|
|
227
|
+
if (ms === false || ms <= 0) {
|
|
228
|
+
intervalIteration = 0;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
intervalIteration++;
|
|
232
|
+
clearTimeout(intervalTimer);
|
|
233
|
+
intervalTimer = setTimeout(() => {
|
|
234
|
+
refetch();
|
|
235
|
+
}, ms);
|
|
236
|
+
}
|
|
237
|
+
let visibilityHandler;
|
|
238
|
+
if (hasInterval && enabled && !isSSR() && typeof document !== "undefined") {
|
|
239
|
+
visibilityHandler = () => {
|
|
240
|
+
if (document.visibilityState === "hidden") {
|
|
241
|
+
intervalPaused = true;
|
|
242
|
+
clearTimeout(intervalTimer);
|
|
243
|
+
} else {
|
|
244
|
+
intervalPaused = false;
|
|
245
|
+
refetch();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
document.addEventListener("visibilitychange", visibilityHandler);
|
|
249
|
+
}
|
|
250
|
+
function handleFetchPromise(promise, id, key) {
|
|
251
|
+
promise.then((result) => {
|
|
252
|
+
inflight.delete(key);
|
|
253
|
+
inflightKeys.delete(key);
|
|
254
|
+
if (id !== fetchId)
|
|
255
|
+
return;
|
|
256
|
+
cache.set(key, result);
|
|
257
|
+
data.value = result;
|
|
258
|
+
loading.value = false;
|
|
259
|
+
revalidating.value = false;
|
|
260
|
+
scheduleInterval();
|
|
261
|
+
}, (err) => {
|
|
262
|
+
inflight.delete(key);
|
|
263
|
+
inflightKeys.delete(key);
|
|
264
|
+
if (id !== fetchId)
|
|
265
|
+
return;
|
|
266
|
+
error.value = err;
|
|
267
|
+
loading.value = false;
|
|
268
|
+
revalidating.value = false;
|
|
269
|
+
scheduleInterval();
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function startFetch(fetchPromise, key) {
|
|
273
|
+
const id = ++fetchId;
|
|
274
|
+
untrack(() => {
|
|
275
|
+
if (data.value !== undefined) {
|
|
276
|
+
revalidating.value = true;
|
|
277
|
+
} else {
|
|
278
|
+
loading.value = true;
|
|
279
|
+
}
|
|
280
|
+
error.value = undefined;
|
|
281
|
+
});
|
|
282
|
+
const existing = inflight.get(key);
|
|
283
|
+
if (existing) {
|
|
284
|
+
handleFetchPromise(existing, id, key);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
inflight.set(key, fetchPromise);
|
|
288
|
+
inflightKeys.add(key);
|
|
289
|
+
handleFetchPromise(fetchPromise, id, key);
|
|
290
|
+
}
|
|
291
|
+
function refetch() {
|
|
292
|
+
const key = getCacheKey();
|
|
293
|
+
cache.delete(key);
|
|
294
|
+
inflight.delete(key);
|
|
295
|
+
refetchTrigger.value = refetchTrigger.peek() + 1;
|
|
296
|
+
}
|
|
297
|
+
let disposeFn;
|
|
298
|
+
if (enabled) {
|
|
299
|
+
let isFirst = true;
|
|
300
|
+
disposeFn = lifecycleEffect(() => {
|
|
301
|
+
refetchTrigger.value;
|
|
302
|
+
if (isFirst && ssrHydrated) {
|
|
303
|
+
isFirst = false;
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (isFirst && navPrefetchDeferred) {
|
|
307
|
+
if (customKey) {
|
|
308
|
+
const cached = untrack(() => cache.get(customKey));
|
|
309
|
+
if (cached !== undefined) {
|
|
310
|
+
untrack(() => {
|
|
311
|
+
data.value = cached;
|
|
312
|
+
loading.value = false;
|
|
313
|
+
});
|
|
314
|
+
isFirst = false;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
const trackPromise = callThunkWithCapture();
|
|
319
|
+
trackPromise.catch(() => {});
|
|
320
|
+
const derivedKey = untrack(() => getCacheKey());
|
|
321
|
+
const cached = untrack(() => cache.get(derivedKey));
|
|
322
|
+
if (cached !== undefined) {
|
|
323
|
+
untrack(() => {
|
|
324
|
+
data.value = cached;
|
|
325
|
+
loading.value = false;
|
|
326
|
+
});
|
|
327
|
+
isFirst = false;
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
isFirst = false;
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (customKey) {
|
|
335
|
+
const existing = untrack(() => inflight.get(customKey));
|
|
336
|
+
if (existing) {
|
|
337
|
+
const id = ++fetchId;
|
|
338
|
+
untrack(() => {
|
|
339
|
+
if (data.value !== undefined) {
|
|
340
|
+
revalidating.value = true;
|
|
341
|
+
} else {
|
|
342
|
+
loading.value = true;
|
|
343
|
+
}
|
|
344
|
+
error.value = undefined;
|
|
345
|
+
});
|
|
346
|
+
handleFetchPromise(existing, id, customKey);
|
|
347
|
+
isFirst = false;
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const promise = callThunkWithCapture();
|
|
352
|
+
const key = untrack(() => getCacheKey());
|
|
353
|
+
if (!customKey) {
|
|
354
|
+
const existing = untrack(() => inflight.get(key));
|
|
355
|
+
if (existing) {
|
|
356
|
+
promise.catch(() => {});
|
|
357
|
+
const id = ++fetchId;
|
|
358
|
+
untrack(() => {
|
|
359
|
+
if (data.value !== undefined) {
|
|
360
|
+
revalidating.value = true;
|
|
361
|
+
} else {
|
|
362
|
+
loading.value = true;
|
|
363
|
+
}
|
|
364
|
+
error.value = undefined;
|
|
365
|
+
});
|
|
366
|
+
handleFetchPromise(existing, id, key);
|
|
367
|
+
isFirst = false;
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
const isNavigation = ssrHydrationCleanup !== null;
|
|
372
|
+
const shouldCheckCache = isNavigation || (isFirst ? !!customKey : !customKey);
|
|
373
|
+
if (shouldCheckCache) {
|
|
374
|
+
const cached = untrack(() => cache.get(key));
|
|
375
|
+
if (cached !== undefined) {
|
|
376
|
+
promise.catch(() => {});
|
|
377
|
+
untrack(() => {
|
|
378
|
+
data.value = cached;
|
|
379
|
+
loading.value = false;
|
|
380
|
+
error.value = undefined;
|
|
381
|
+
});
|
|
382
|
+
isFirst = false;
|
|
383
|
+
scheduleInterval();
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (isFirst && initialData !== undefined) {
|
|
388
|
+
promise.catch(() => {});
|
|
389
|
+
isFirst = false;
|
|
390
|
+
scheduleInterval();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
isFirst = false;
|
|
394
|
+
if (debounceMs !== undefined && debounceMs > 0) {
|
|
395
|
+
clearTimeout(debounceTimer);
|
|
396
|
+
promise.catch(() => {});
|
|
397
|
+
debounceTimer = setTimeout(() => {
|
|
398
|
+
startFetch(promise, key);
|
|
399
|
+
}, debounceMs);
|
|
400
|
+
} else {
|
|
401
|
+
startFetch(promise, key);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function dispose() {
|
|
406
|
+
disposeFn?.();
|
|
407
|
+
ssrHydrationCleanup?.();
|
|
408
|
+
clearTimeout(debounceTimer);
|
|
409
|
+
clearTimeout(intervalTimer);
|
|
410
|
+
if (visibilityHandler && typeof document !== "undefined") {
|
|
411
|
+
document.removeEventListener("visibilitychange", visibilityHandler);
|
|
412
|
+
}
|
|
413
|
+
fetchId++;
|
|
414
|
+
for (const key of inflightKeys) {
|
|
415
|
+
inflight.delete(key);
|
|
416
|
+
}
|
|
417
|
+
inflightKeys.clear();
|
|
418
|
+
}
|
|
419
|
+
_tryOnCleanup(dispose);
|
|
420
|
+
return {
|
|
421
|
+
data,
|
|
422
|
+
loading,
|
|
423
|
+
revalidating,
|
|
424
|
+
error,
|
|
425
|
+
refetch,
|
|
426
|
+
revalidate: refetch,
|
|
427
|
+
dispose
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/query/query-match.ts
|
|
432
|
+
var cache = new WeakMap;
|
|
433
|
+
function queryMatch(queryResult, handlers) {
|
|
434
|
+
const key = queryResult;
|
|
435
|
+
const existing = cache.get(key);
|
|
436
|
+
if (existing && !existing.disposed) {
|
|
437
|
+
existing.handlers = handlers;
|
|
438
|
+
return existing.wrapper;
|
|
439
|
+
}
|
|
440
|
+
if (existing) {
|
|
441
|
+
cache.delete(key);
|
|
442
|
+
}
|
|
443
|
+
const wrapper = getAdapter().createElement("span");
|
|
444
|
+
wrapper.style.display = "contents";
|
|
445
|
+
const entry = { wrapper, handlers, disposed: false };
|
|
446
|
+
cache.set(key, entry);
|
|
447
|
+
let currentBranch = null;
|
|
448
|
+
let branchCleanups = [];
|
|
449
|
+
const outerScope = pushScope();
|
|
450
|
+
domEffect(() => {
|
|
451
|
+
const isLoading = queryResult.loading.value;
|
|
452
|
+
const err = queryResult.error.value;
|
|
453
|
+
const dataValue = queryResult.data.value;
|
|
454
|
+
let branch;
|
|
455
|
+
if (isLoading || err === undefined && dataValue === undefined) {
|
|
456
|
+
branch = "loading";
|
|
457
|
+
} else if (err !== undefined) {
|
|
458
|
+
branch = "error";
|
|
459
|
+
} else {
|
|
460
|
+
branch = "data";
|
|
461
|
+
}
|
|
462
|
+
if (branch === currentBranch && branch !== "data") {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
runCleanups(branchCleanups);
|
|
466
|
+
while (wrapper.firstChild) {
|
|
467
|
+
wrapper.removeChild(wrapper.firstChild);
|
|
468
|
+
}
|
|
469
|
+
currentBranch = branch;
|
|
470
|
+
const scope = pushScope();
|
|
471
|
+
let branchResult = null;
|
|
472
|
+
if (branch === "loading") {
|
|
473
|
+
branchResult = entry.handlers.loading();
|
|
474
|
+
} else if (branch === "error") {
|
|
475
|
+
branchResult = entry.handlers.error(err);
|
|
476
|
+
} else {
|
|
477
|
+
const dataSignal = queryResult.data;
|
|
478
|
+
const dataProxy = new Proxy({}, {
|
|
479
|
+
get(_target, prop, receiver) {
|
|
480
|
+
const current = dataSignal.value;
|
|
481
|
+
if (current == null)
|
|
482
|
+
return;
|
|
483
|
+
const value = Reflect.get(current, prop, receiver);
|
|
484
|
+
if (typeof value === "function") {
|
|
485
|
+
return value.bind(current);
|
|
486
|
+
}
|
|
487
|
+
return value;
|
|
488
|
+
},
|
|
489
|
+
has(_target, prop) {
|
|
490
|
+
const current = dataSignal.value;
|
|
491
|
+
if (current == null)
|
|
492
|
+
return false;
|
|
493
|
+
return Reflect.has(current, prop);
|
|
494
|
+
},
|
|
495
|
+
ownKeys() {
|
|
496
|
+
const current = dataSignal.value;
|
|
497
|
+
if (current == null)
|
|
498
|
+
return [];
|
|
499
|
+
return Reflect.ownKeys(current);
|
|
500
|
+
},
|
|
501
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
502
|
+
const current = dataSignal.value;
|
|
503
|
+
if (current == null)
|
|
504
|
+
return;
|
|
505
|
+
return Reflect.getOwnPropertyDescriptor(current, prop);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
branchResult = entry.handlers.data(dataProxy);
|
|
509
|
+
}
|
|
510
|
+
popScope();
|
|
511
|
+
branchCleanups = scope;
|
|
512
|
+
if (branchResult != null && isRenderNode(branchResult)) {
|
|
513
|
+
wrapper.appendChild(branchResult);
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
popScope();
|
|
517
|
+
const dispose = () => {
|
|
518
|
+
entry.disposed = true;
|
|
519
|
+
runCleanups(branchCleanups);
|
|
520
|
+
runCleanups(outerScope);
|
|
521
|
+
cache.delete(key);
|
|
522
|
+
};
|
|
523
|
+
wrapper.dispose = dispose;
|
|
524
|
+
_tryOnCleanup(dispose);
|
|
525
|
+
return wrapper;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export { MemoryCache, deriveKey, query, queryMatch };
|