tsdf 18.0.0 → 18.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/dist/main.d.ts +2 -2
- package/dist/main.js +7 -7
- package/docs/mutations.md +7 -6
- package/package.json +2 -2
package/dist/main.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ type StoreManagerStoreDefaults = {
|
|
|
44
44
|
/** Default minimum interval between low-priority fetches for attached stores. */readonly lowPriorityThrottleMs: number; /** Default coalescing window used by attached stores when they do not override it. */
|
|
45
45
|
readonly baseCoalescingWindowMs: number; /** Extra browser-tab coalescing delay applied only while a tab is in the background. */
|
|
46
46
|
readonly backgroundCoalescingDelayMs: number; /** Default adaptive throttle for real-time updates in attached stores. */
|
|
47
|
-
readonly dynamicRealtimeThrottleMs: DynamicRealtimeThrottleMs; /** Shared window-close blocker
|
|
47
|
+
readonly dynamicRealtimeThrottleMs: DynamicRealtimeThrottleMs; /** Shared window-close blocker held by every mutation in attached stores from start until it settles. */
|
|
48
48
|
readonly blockWindowClose: BlockWindowCloseHandler | null; /** Default focus revalidation policy for attached stores. */
|
|
49
49
|
readonly revalidateOnWindowFocus: boolean | (() => boolean) | undefined;
|
|
50
50
|
};
|
|
@@ -106,7 +106,7 @@ type CreateStoreManagerOptions<TUploadRef extends ValidPayload = ValidPayload> =
|
|
|
106
106
|
lowPriorityThrottleMs?: number; /** Default coalescing window for attached stores. Defaults to 16ms. */
|
|
107
107
|
baseCoalescingWindowMs?: number; /** Extra browser-tab coalescing delay applied only while a tab is in the background. Defaults to 3000ms. */
|
|
108
108
|
backgroundCoalescingDelayMs?: number; /** Default adaptive throttle for real-time updates in attached stores. Store-level values override it. */
|
|
109
|
-
dynamicRealtimeThrottleMs?: DynamicRealtimeThrottleMs; /** Shared window-close blocker
|
|
109
|
+
dynamicRealtimeThrottleMs?: DynamicRealtimeThrottleMs; /** Shared window-close blocker held by every mutation in attached stores from start until it settles. Pass `null` to disable. */
|
|
110
110
|
blockWindowClose?: BlockWindowCloseHandler | null; /** Global fallback for persistent storage failures when a store does not provide its own handler. */
|
|
111
111
|
onPersistentStorageError?: PersistentStorageErrorHandler; /** Global fallback for mutation failures when a store does not provide its own handler. */
|
|
112
112
|
onMutationError?: StoreManagerMutationErrorHandler; /** Default focus revalidation policy for attached stores. Store-level values override it. */
|
package/dist/main.js
CHANGED
|
@@ -12,7 +12,7 @@ import { Result, isResult, resultify, unknownToError } from "t-result";
|
|
|
12
12
|
import { Store, useSubscribeToStore } from "t-state";
|
|
13
13
|
import { useOnChange } from "@ls-stack/react-utils/useOnChange";
|
|
14
14
|
import { useConst } from "@ls-stack/react-utils/useConst";
|
|
15
|
-
import {
|
|
15
|
+
import { useLatestCb } from "@ls-stack/react-utils/useLatestValue";
|
|
16
16
|
import { useTimeout } from "@ls-stack/react-utils/useTimeout";
|
|
17
17
|
import { isObject, isPromise } from "@ls-stack/utils/typeGuards";
|
|
18
18
|
import { rc_array, rc_boolean, rc_literals, rc_number, rc_object, rc_parse, rc_parse_json, rc_record, rc_string, rc_union, rc_unknown } from "runcheck";
|
|
@@ -146,8 +146,8 @@ function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadIte
|
|
|
146
146
|
const ignoreSetWillBeRefetched = useRef(false);
|
|
147
147
|
const itemWasRefetched = useConst(() => /* @__PURE__ */ new Set());
|
|
148
148
|
if (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) setWillBeRefetched(true);
|
|
149
|
-
const
|
|
150
|
-
const latestLoadItemFallback =
|
|
149
|
+
const getIsLoadingOrRefetching = useLatestCb(() => listIsLoading || isRefetching);
|
|
150
|
+
const latestLoadItemFallback = useLatestCb(loadItemFallback);
|
|
151
151
|
useEffect(() => {
|
|
152
152
|
if (isRefetching) {
|
|
153
153
|
if (itemId) itemWasRefetched.add(itemId);
|
|
@@ -165,8 +165,8 @@ function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadIte
|
|
|
165
165
|
useEffect(() => {
|
|
166
166
|
if (willBeRefetched) {
|
|
167
167
|
callFallbackLoadItemTimeout.call(() => {
|
|
168
|
-
if (!
|
|
169
|
-
latestLoadItemFallback
|
|
168
|
+
if (!getIsLoadingOrRefetching()) {
|
|
169
|
+
latestLoadItemFallback();
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
});
|
|
@@ -185,7 +185,7 @@ function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadIte
|
|
|
185
185
|
}, [
|
|
186
186
|
resetWillBeRefetchedTimeout,
|
|
187
187
|
willBeRefetched,
|
|
188
|
-
|
|
188
|
+
getIsLoadingOrRefetching,
|
|
189
189
|
latestLoadItemFallback,
|
|
190
190
|
callFallbackLoadItemTimeout
|
|
191
191
|
]);
|
|
@@ -8596,8 +8596,8 @@ async function performMutationWithLifecycle(startMutation, mutation, onError, op
|
|
|
8596
8596
|
endMutation();
|
|
8597
8597
|
return Result.err(mutationSkipped);
|
|
8598
8598
|
}
|
|
8599
|
+
unblockWindowClose = blockWindowClose?.().unblock ?? null;
|
|
8599
8600
|
if (debounce) {
|
|
8600
|
-
unblockWindowClose = blockWindowClose?.().unblock ?? null;
|
|
8601
8601
|
const debounceKey = getCompositeKey([debounce.context, debounce.payload]);
|
|
8602
8602
|
const groupRollbacks = pendingDebounceRollbacks.get(debounceKey) ?? [];
|
|
8603
8603
|
groupRollbacks.push(...rollbacks);
|
package/docs/mutations.md
CHANGED
|
@@ -83,11 +83,12 @@ The payload can be:
|
|
|
83
83
|
|
|
84
84
|
1. **Lock**: The scheduler is locked for the affected items/queries, preventing concurrent fetches. An in-flight fetch for them is aborted so it can't commit stale data, and it is retried once the lock is released. Calls awaiting the aborted fetch (e.g. `awaitFetch`, `getItemFromStateOrFetch`) resolve with the retry's result
|
|
85
85
|
2. **Optimistic update**: If provided, runs immediately. If it returns `false`, the mutation is cancelled
|
|
86
|
-
3. **
|
|
87
|
-
4. **
|
|
88
|
-
5. **
|
|
89
|
-
6. **On
|
|
90
|
-
7. **
|
|
86
|
+
3. **Block window close**: If the manager `blockWindowClose` option is set, window close is blocked until the mutation settles (including the debounce wait)
|
|
87
|
+
4. **Debounce** (optional): Waits for `ms` milliseconds
|
|
88
|
+
5. **Execute mutation**: The async mutation function runs
|
|
89
|
+
6. **On success**: Calls `onSuccess`, optionally invalidates data
|
|
90
|
+
7. **On error**: Rolls back optimistic state, normalizes the error, and calls `onMutationError` with the `silentErrors` flag
|
|
91
|
+
8. **Unlock**: The scheduler is unlocked, pending fetches resume
|
|
91
92
|
|
|
92
93
|
## Return Value
|
|
93
94
|
|
|
@@ -157,7 +158,7 @@ await store.performMutation({
|
|
|
157
158
|
});
|
|
158
159
|
```
|
|
159
160
|
|
|
160
|
-
|
|
161
|
+
The window close stays blocked during the debounce period too, so a pending debounced mutation isn't lost if the tab is closed.
|
|
161
162
|
|
|
162
163
|
Superseded calls never send their mutation, so their optimistic updates are handed to the call that superseded them: if that call fails, the state goes back to what it was before the first superseded call.
|
|
163
164
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdf",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.1.0",
|
|
4
4
|
"description": "A data fetching solution based on t-state",
|
|
5
5
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
6
6
|
"author": "Lucas Santos",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@evtmitter/react": "^0.1.0",
|
|
72
72
|
"@ls-stack/browser-utils": "^0.3.5",
|
|
73
|
-
"@ls-stack/react-utils": "^0.13.
|
|
73
|
+
"@ls-stack/react-utils": "^0.13.3",
|
|
74
74
|
"@ls-stack/utils": "^4.0.0",
|
|
75
75
|
"@standard-schema/spec": "^1.1.0",
|
|
76
76
|
"evtmitter": "^1.0.2",
|