tsdf 17.0.0-alpha.15 → 17.0.0-alpha.16
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/main.js +35 -58
- package/docs/invalidation.md +1 -1
- package/docs/real-time-updates.md +3 -3
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -7708,15 +7708,15 @@ async function performMutationWithLifecycle(startMutation, mutation, onError, op
|
|
|
7708
7708
|
//#endregion
|
|
7709
7709
|
//#region src/utils/storeFocusLifecycle.ts
|
|
7710
7710
|
/** @internal */
|
|
7711
|
-
function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs,
|
|
7711
|
+
function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, onWindowFocus, onWindowFocusRevalidate, onTransportReconnectRevalidate, debug) {
|
|
7712
7712
|
let cleanupFocusListener = null;
|
|
7713
|
-
let
|
|
7713
|
+
let cleanupReconnectFocusListener = null;
|
|
7714
7714
|
let reconnectCooldownTimeoutId = null;
|
|
7715
|
-
let
|
|
7715
|
+
let hasPendingReconnectRevalidateOnFocus = false;
|
|
7716
7716
|
let lastTransportReconnectRevalidateAt = Number.NEGATIVE_INFINITY;
|
|
7717
|
-
function
|
|
7718
|
-
|
|
7719
|
-
|
|
7717
|
+
function clearReconnectFocusListener() {
|
|
7718
|
+
cleanupReconnectFocusListener?.();
|
|
7719
|
+
cleanupReconnectFocusListener = null;
|
|
7720
7720
|
}
|
|
7721
7721
|
function clearReconnectCooldownTimeout() {
|
|
7722
7722
|
if (reconnectCooldownTimeoutId !== null) {
|
|
@@ -7745,26 +7745,25 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
|
|
|
7745
7745
|
lastTransportReconnectRevalidateAt = Date.now();
|
|
7746
7746
|
onTransportReconnectRevalidate();
|
|
7747
7747
|
}
|
|
7748
|
-
function
|
|
7749
|
-
if (
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
hasPendingReconnectRevalidate = false;
|
|
7748
|
+
function ensureReconnectFocusListener() {
|
|
7749
|
+
if (cleanupReconnectFocusListener) return;
|
|
7750
|
+
cleanupReconnectFocusListener = onWindowFocus(() => {
|
|
7751
|
+
clearReconnectFocusListener();
|
|
7752
|
+
if (!hasPendingReconnectRevalidateOnFocus) return;
|
|
7753
|
+
hasPendingReconnectRevalidateOnFocus = false;
|
|
7755
7754
|
runTransportReconnectRevalidate();
|
|
7756
7755
|
});
|
|
7757
7756
|
}
|
|
7758
7757
|
function flushTransportReconnectRevalidate() {
|
|
7759
7758
|
clearReconnectCooldownTimeout();
|
|
7760
|
-
if (
|
|
7761
|
-
|
|
7762
|
-
|
|
7759
|
+
if (getWindowIsFocused()) {
|
|
7760
|
+
hasPendingReconnectRevalidateOnFocus = false;
|
|
7761
|
+
clearReconnectFocusListener();
|
|
7763
7762
|
runTransportReconnectRevalidate();
|
|
7764
7763
|
return;
|
|
7765
7764
|
}
|
|
7766
|
-
|
|
7767
|
-
|
|
7765
|
+
hasPendingReconnectRevalidateOnFocus = true;
|
|
7766
|
+
ensureReconnectFocusListener();
|
|
7768
7767
|
}
|
|
7769
7768
|
function scheduleTrailingTransportReconnectRevalidate() {
|
|
7770
7769
|
clearReconnectCooldownTimeout();
|
|
@@ -7776,9 +7775,9 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
|
|
|
7776
7775
|
function reset() {
|
|
7777
7776
|
cleanupFocusListener?.();
|
|
7778
7777
|
cleanupFocusListener = null;
|
|
7779
|
-
|
|
7778
|
+
clearReconnectFocusListener();
|
|
7780
7779
|
clearReconnectCooldownTimeout();
|
|
7781
|
-
|
|
7780
|
+
hasPendingReconnectRevalidateOnFocus = false;
|
|
7782
7781
|
lastTransportReconnectRevalidateAt = Number.NEGATIVE_INFINITY;
|
|
7783
7782
|
if (!revalidateOnWindowFocus) return;
|
|
7784
7783
|
if (usesRealTimeUpdates) {
|
|
@@ -7807,9 +7806,9 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
|
|
|
7807
7806
|
function dispose() {
|
|
7808
7807
|
cleanupFocusListener?.();
|
|
7809
7808
|
cleanupFocusListener = null;
|
|
7810
|
-
|
|
7809
|
+
clearReconnectFocusListener();
|
|
7811
7810
|
clearReconnectCooldownTimeout();
|
|
7812
|
-
|
|
7811
|
+
hasPendingReconnectRevalidateOnFocus = false;
|
|
7813
7812
|
lastTransportReconnectRevalidateAt = Number.NEGATIVE_INFINITY;
|
|
7814
7813
|
}
|
|
7815
7814
|
function onTransportReconnect() {
|
|
@@ -7818,7 +7817,7 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
|
|
|
7818
7817
|
flushTransportReconnectRevalidate();
|
|
7819
7818
|
return;
|
|
7820
7819
|
}
|
|
7821
|
-
if (
|
|
7820
|
+
if (hasPendingReconnectRevalidateOnFocus) return;
|
|
7822
7821
|
if (Date.now() - lastTransportReconnectRevalidateAt >= transportReconnectCooldownMs) {
|
|
7823
7822
|
flushTransportReconnectRevalidate();
|
|
7824
7823
|
return;
|
|
@@ -7833,25 +7832,6 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
|
|
|
7833
7832
|
};
|
|
7834
7833
|
}
|
|
7835
7834
|
//#endregion
|
|
7836
|
-
//#region src/utils/windowRevalidation.ts
|
|
7837
|
-
/** @internal */
|
|
7838
|
-
function isWindowVisible() {
|
|
7839
|
-
return document.visibilityState === "visible";
|
|
7840
|
-
}
|
|
7841
|
-
/** @internal */
|
|
7842
|
-
function onWindowVisible(handler) {
|
|
7843
|
-
window.addEventListener("focus", handler);
|
|
7844
|
-
window.addEventListener("pageshow", handler);
|
|
7845
|
-
window.addEventListener("visibilitychange", handler);
|
|
7846
|
-
document.addEventListener("visibilitychange", handler);
|
|
7847
|
-
return () => {
|
|
7848
|
-
window.removeEventListener("focus", handler);
|
|
7849
|
-
window.removeEventListener("pageshow", handler);
|
|
7850
|
-
window.removeEventListener("visibilitychange", handler);
|
|
7851
|
-
document.removeEventListener("visibilitychange", handler);
|
|
7852
|
-
};
|
|
7853
|
-
}
|
|
7854
|
-
//#endregion
|
|
7855
7835
|
//#region src/collectionStore/collectionCacheLimits.ts
|
|
7856
7836
|
/** @internal */
|
|
7857
7837
|
function createCollectionCacheLimits(store, maxItems, itemCacheRuntime, isProtectedFromEviction, cleanupItemResources, onStateCleanup) {
|
|
@@ -8666,7 +8646,6 @@ function createCollectionStore(storeOptions) {
|
|
|
8666
8646
|
return false;
|
|
8667
8647
|
}
|
|
8668
8648
|
const getWindowIsFocused = testOptions?.getWindowIsFocused ?? isWindowFocused;
|
|
8669
|
-
const getWindowCanRunRevalidation = testOptions?.getWindowCanRunRevalidation ?? isWindowVisible;
|
|
8670
8649
|
function runWithoutBroadcast(callback) {
|
|
8671
8650
|
remoteApplyDepth++;
|
|
8672
8651
|
try {
|
|
@@ -9227,7 +9206,7 @@ function createCollectionStore(storeOptions) {
|
|
|
9227
9206
|
if (!offline && result.ok && result.value.kind === "online") return Result.ok(result.value.data);
|
|
9228
9207
|
return result;
|
|
9229
9208
|
}
|
|
9230
|
-
const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs,
|
|
9209
|
+
const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, testOptions?.onWindowFocus ?? onWindowFocus, () => {
|
|
9231
9210
|
invalidateItem(() => true, "lowPriority");
|
|
9232
9211
|
}, () => {
|
|
9233
9212
|
invalidateItem(() => true, "realtimeUpdate");
|
|
@@ -9250,12 +9229,12 @@ function createCollectionStore(storeOptions) {
|
|
|
9250
9229
|
* items need to be revalidated.
|
|
9251
9230
|
*
|
|
9252
9231
|
* - No-op when `usesRealTimeUpdates` is `false`.
|
|
9253
|
-
* - If the window is
|
|
9232
|
+
* - If the window is focused, the first reconnect invalidates all items
|
|
9254
9233
|
* immediately with `realtimeUpdate` priority.
|
|
9255
9234
|
* - Additional reconnects within `transportReconnectCooldownMs` are
|
|
9256
9235
|
* coalesced into one trailing invalidation.
|
|
9257
|
-
* - If the window is
|
|
9258
|
-
* window
|
|
9236
|
+
* - If the window is **not** focused, reconnect invalidation waits until the
|
|
9237
|
+
* next window focus event.
|
|
9259
9238
|
*/
|
|
9260
9239
|
function onTransportReconnect() {
|
|
9261
9240
|
if (isDisposed) return;
|
|
@@ -9698,7 +9677,6 @@ function createDocumentStore(storeOptions) {
|
|
|
9698
9677
|
const events = evtmitter();
|
|
9699
9678
|
const storeEvents = evtmitter();
|
|
9700
9679
|
const getWindowIsFocused = testOptions?.getWindowIsFocused ?? isWindowFocused;
|
|
9701
|
-
const getWindowCanRunRevalidation = testOptions?.getWindowCanRunRevalidation ?? isWindowVisible;
|
|
9702
9680
|
function runWithoutBroadcast(callback) {
|
|
9703
9681
|
remoteApplyDepth++;
|
|
9704
9682
|
try {
|
|
@@ -9859,7 +9837,7 @@ function createDocumentStore(storeOptions) {
|
|
|
9859
9837
|
usesRealTimeUpdates
|
|
9860
9838
|
});
|
|
9861
9839
|
if (initialStatus !== "idle" || initialData !== null || initialError !== null) scheduler.setLastFetchStartTimeForRequest(DOC_REQUEST_ID, testOptions?.initialLastFetchStartTime ?? 0);
|
|
9862
|
-
const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs,
|
|
9840
|
+
const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, testOptions?.onWindowFocus ?? onWindowFocus, () => {
|
|
9863
9841
|
invalidateData("lowPriority");
|
|
9864
9842
|
}, () => {
|
|
9865
9843
|
invalidateData("realtimeUpdate");
|
|
@@ -9937,12 +9915,12 @@ function createDocumentStore(storeOptions) {
|
|
|
9937
9915
|
* needs to be revalidated.
|
|
9938
9916
|
*
|
|
9939
9917
|
* - No-op when `usesRealTimeUpdates` is `false`.
|
|
9940
|
-
* - If the window is
|
|
9941
|
-
* `realtimeUpdate` priority.
|
|
9918
|
+
* - If the window is focused, the first reconnect invalidates immediately
|
|
9919
|
+
* with `realtimeUpdate` priority.
|
|
9942
9920
|
* - Additional reconnects within `transportReconnectCooldownMs` are coalesced
|
|
9943
9921
|
* into one trailing invalidation.
|
|
9944
|
-
* - If the window is
|
|
9945
|
-
* window
|
|
9922
|
+
* - If the window is **not** focused, reconnect invalidation waits until the
|
|
9923
|
+
* next window focus event.
|
|
9946
9924
|
*/
|
|
9947
9925
|
function onTransportReconnect() {
|
|
9948
9926
|
if (isDisposed) return;
|
|
@@ -14816,7 +14794,6 @@ function createListQueryStore(storeOptions) {
|
|
|
14816
14794
|
return false;
|
|
14817
14795
|
}
|
|
14818
14796
|
const getWindowIsFocused = testOptions?.getWindowIsFocused ?? isWindowFocused;
|
|
14819
|
-
const getWindowCanRunRevalidation = testOptions?.getWindowCanRunRevalidation ?? isWindowVisible;
|
|
14820
14797
|
function runWithoutBroadcast(callback) {
|
|
14821
14798
|
remoteApplyDepth++;
|
|
14822
14799
|
try {
|
|
@@ -15371,7 +15348,7 @@ function createListQueryStore(storeOptions) {
|
|
|
15371
15348
|
function useFindItem$1(findItemFn, options = {}) {
|
|
15372
15349
|
return useFindItem(findItemFn, options, store, registerActiveStandaloneItems, touchItems);
|
|
15373
15350
|
}
|
|
15374
|
-
const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs,
|
|
15351
|
+
const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, testOptions?.onWindowFocus ?? onWindowFocus, () => {
|
|
15375
15352
|
invalidateQueryAndItems({
|
|
15376
15353
|
all: true,
|
|
15377
15354
|
type: "lowPriority"
|
|
@@ -15406,12 +15383,12 @@ function createListQueryStore(storeOptions) {
|
|
|
15406
15383
|
* queries and items need to be revalidated.
|
|
15407
15384
|
*
|
|
15408
15385
|
* - No-op when `usesRealTimeUpdates` is `false`.
|
|
15409
|
-
* - If the window is
|
|
15386
|
+
* - If the window is focused, the first reconnect invalidates all queries
|
|
15410
15387
|
* and items immediately with `realtimeUpdate` priority.
|
|
15411
15388
|
* - Additional reconnects within `transportReconnectCooldownMs` are
|
|
15412
15389
|
* coalesced into one trailing invalidation.
|
|
15413
|
-
* - If the window is
|
|
15414
|
-
* window
|
|
15390
|
+
* - If the window is **not** focused, reconnect invalidation waits until the
|
|
15391
|
+
* next window focus event.
|
|
15415
15392
|
*/
|
|
15416
15393
|
function onTransportReconnect() {
|
|
15417
15394
|
if (isDisposed) return;
|
package/docs/invalidation.md
CHANGED
|
@@ -132,4 +132,4 @@ TSDF automatically invalidates data in these scenarios:
|
|
|
132
132
|
- **Mutation error**: After a failed mutation, affected data is invalidated to revert optimistic updates
|
|
133
133
|
- **Mutation success with `revalidateOnSuccess`**: Affected data is invalidated to fetch the server's actual state
|
|
134
134
|
- **Window focus**: When `revalidateOnWindowFocus` is enabled, all data is invalidated with `lowPriority`
|
|
135
|
-
- **Transport reconnect**: When `onTransportReconnect()` is called, all data is invalidated with `realtimeUpdate` priority
|
|
135
|
+
- **Transport reconnect**: When `onTransportReconnect()` is called, all data is invalidated with `realtimeUpdate` priority. See [Real-Time Updates](./real-time-updates.md)
|
|
@@ -104,9 +104,9 @@ Store-level `store.onTransportReconnect()` remains available for stores backed b
|
|
|
104
104
|
|
|
105
105
|
Behavior:
|
|
106
106
|
|
|
107
|
-
- If the
|
|
108
|
-
- If the
|
|
109
|
-
- Multiple reconnect calls while
|
|
107
|
+
- If the window is **focused**: all data is invalidated immediately with `realtimeUpdate` priority
|
|
108
|
+
- If the window is **not focused**: invalidation is deferred until the window regains focus
|
|
109
|
+
- Multiple reconnect calls while unfocused are coalesced (only one invalidation fires on focus)
|
|
110
110
|
- This is a no-op when `usesRealTimeUpdates` is `false`
|
|
111
111
|
|
|
112
112
|
## Pattern: WebSocket Integration
|