@tanstack/query-core 5.91.2 → 5.94.4
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/package.json +1 -1
- package/build/legacy/_tsup-dts-rollup.d.cts +0 -2229
- package/build/legacy/_tsup-dts-rollup.d.ts +0 -2229
- package/build/legacy/chunk-PXG64RU4.js +0 -25
- package/build/legacy/chunk-PXG64RU4.js.map +0 -1
- package/build/legacy/environmentManager.cjs +0 -48
- package/build/legacy/environmentManager.cjs.map +0 -1
- package/build/legacy/environmentManager.d.cts +0 -2
- package/build/legacy/environmentManager.d.ts +0 -2
- package/build/legacy/environmentManager.js +0 -25
- package/build/legacy/environmentManager.js.map +0 -1
- package/build/legacy/focusManager.cjs +0 -107
- package/build/legacy/focusManager.cjs.map +0 -1
- package/build/legacy/focusManager.d.cts +0 -2
- package/build/legacy/focusManager.d.ts +0 -2
- package/build/legacy/focusManager.js +0 -80
- package/build/legacy/focusManager.js.map +0 -1
- package/build/legacy/hydration.cjs +0 -178
- package/build/legacy/hydration.cjs.map +0 -1
- package/build/legacy/hydration.d.cts +0 -7
- package/build/legacy/hydration.d.ts +0 -7
- package/build/legacy/hydration.js +0 -152
- package/build/legacy/hydration.js.map +0 -1
- package/build/legacy/index.cjs +0 -113
- package/build/legacy/index.cjs.map +0 -1
- package/build/legacy/index.d.cts +0 -142
- package/build/legacy/index.d.ts +0 -142
- package/build/legacy/index.js +0 -75
- package/build/legacy/index.js.map +0 -1
- package/build/legacy/infiniteQueryBehavior.cjs +0 -146
- package/build/legacy/infiniteQueryBehavior.cjs.map +0 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +0 -3
- package/build/legacy/infiniteQueryBehavior.d.ts +0 -3
- package/build/legacy/infiniteQueryBehavior.js +0 -126
- package/build/legacy/infiniteQueryBehavior.js.map +0 -1
- package/build/legacy/infiniteQueryObserver.cjs +0 -93
- package/build/legacy/infiniteQueryObserver.cjs.map +0 -1
- package/build/legacy/infiniteQueryObserver.d.cts +0 -1
- package/build/legacy/infiniteQueryObserver.d.ts +0 -1
- package/build/legacy/infiniteQueryObserver.js +0 -74
- package/build/legacy/infiniteQueryObserver.js.map +0 -1
- package/build/legacy/mutation.cjs +0 -333
- package/build/legacy/mutation.cjs.map +0 -1
- package/build/legacy/mutation.d.cts +0 -4
- package/build/legacy/mutation.d.ts +0 -4
- package/build/legacy/mutation.js +0 -306
- package/build/legacy/mutation.js.map +0 -1
- package/build/legacy/mutationCache.cjs +0 -170
- package/build/legacy/mutationCache.cjs.map +0 -1
- package/build/legacy/mutationCache.d.cts +0 -2
- package/build/legacy/mutationCache.d.ts +0 -2
- package/build/legacy/mutationCache.js +0 -137
- package/build/legacy/mutationCache.js.map +0 -1
- package/build/legacy/mutationObserver.cjs +0 -190
- package/build/legacy/mutationObserver.cjs.map +0 -1
- package/build/legacy/mutationObserver.d.cts +0 -1
- package/build/legacy/mutationObserver.d.ts +0 -1
- package/build/legacy/mutationObserver.js +0 -164
- package/build/legacy/mutationObserver.js.map +0 -1
- package/build/legacy/notifyManager.cjs +0 -113
- package/build/legacy/notifyManager.cjs.map +0 -1
- package/build/legacy/notifyManager.d.cts +0 -3
- package/build/legacy/notifyManager.d.ts +0 -3
- package/build/legacy/notifyManager.js +0 -88
- package/build/legacy/notifyManager.js.map +0 -1
- package/build/legacy/onlineManager.cjs +0 -96
- package/build/legacy/onlineManager.cjs.map +0 -1
- package/build/legacy/onlineManager.d.cts +0 -2
- package/build/legacy/onlineManager.d.ts +0 -2
- package/build/legacy/onlineManager.js +0 -69
- package/build/legacy/onlineManager.js.map +0 -1
- package/build/legacy/queriesObserver.cjs +0 -260
- package/build/legacy/queriesObserver.cjs.map +0 -1
- package/build/legacy/queriesObserver.d.cts +0 -2
- package/build/legacy/queriesObserver.d.ts +0 -2
- package/build/legacy/queriesObserver.js +0 -234
- package/build/legacy/queriesObserver.js.map +0 -1
- package/build/legacy/query.cjs +0 -487
- package/build/legacy/query.cjs.map +0 -1
- package/build/legacy/query.d.cts +0 -10
- package/build/legacy/query.d.ts +0 -10
- package/build/legacy/query.js +0 -468
- package/build/legacy/query.js.map +0 -1
- package/build/legacy/queryCache.cjs +0 -131
- package/build/legacy/queryCache.cjs.map +0 -1
- package/build/legacy/queryCache.d.cts +0 -3
- package/build/legacy/queryCache.d.ts +0 -3
- package/build/legacy/queryCache.js +0 -105
- package/build/legacy/queryCache.js.map +0 -1
- package/build/legacy/queryClient.cjs +0 -349
- package/build/legacy/queryClient.cjs.map +0 -1
- package/build/legacy/queryClient.d.cts +0 -1
- package/build/legacy/queryClient.d.ts +0 -1
- package/build/legacy/queryClient.js +0 -324
- package/build/legacy/queryClient.js.map +0 -1
- package/build/legacy/queryObserver.cjs +0 -516
- package/build/legacy/queryObserver.cjs.map +0 -1
- package/build/legacy/queryObserver.d.cts +0 -1
- package/build/legacy/queryObserver.d.ts +0 -1
- package/build/legacy/queryObserver.js +0 -498
- package/build/legacy/queryObserver.js.map +0 -1
- package/build/legacy/removable.cjs +0 -70
- package/build/legacy/removable.cjs.map +0 -1
- package/build/legacy/removable.d.cts +0 -1
- package/build/legacy/removable.d.ts +0 -1
- package/build/legacy/removable.js +0 -44
- package/build/legacy/removable.js.map +0 -1
- package/build/legacy/retryer.cjs +0 -166
- package/build/legacy/retryer.cjs.map +0 -1
- package/build/legacy/retryer.d.cts +0 -7
- package/build/legacy/retryer.d.ts +0 -7
- package/build/legacy/retryer.js +0 -140
- package/build/legacy/retryer.js.map +0 -1
- package/build/legacy/streamedQuery.cjs +0 -80
- package/build/legacy/streamedQuery.cjs.map +0 -1
- package/build/legacy/streamedQuery.d.cts +0 -1
- package/build/legacy/streamedQuery.d.ts +0 -1
- package/build/legacy/streamedQuery.js +0 -57
- package/build/legacy/streamedQuery.js.map +0 -1
- package/build/legacy/subscribable.cjs +0 -51
- package/build/legacy/subscribable.cjs.map +0 -1
- package/build/legacy/subscribable.d.cts +0 -1
- package/build/legacy/subscribable.d.ts +0 -1
- package/build/legacy/subscribable.js +0 -28
- package/build/legacy/subscribable.js.map +0 -1
- package/build/legacy/thenable.cjs +0 -76
- package/build/legacy/thenable.cjs.map +0 -1
- package/build/legacy/thenable.d.cts +0 -6
- package/build/legacy/thenable.d.ts +0 -6
- package/build/legacy/thenable.js +0 -52
- package/build/legacy/thenable.js.map +0 -1
- package/build/legacy/timeoutManager.cjs +0 -110
- package/build/legacy/timeoutManager.cjs.map +0 -1
- package/build/legacy/timeoutManager.d.cts +0 -7
- package/build/legacy/timeoutManager.d.ts +0 -7
- package/build/legacy/timeoutManager.js +0 -81
- package/build/legacy/timeoutManager.js.map +0 -1
- package/build/legacy/types.cjs +0 -37
- package/build/legacy/types.cjs.map +0 -1
- package/build/legacy/types.d.cts +0 -95
- package/build/legacy/types.d.ts +0 -95
- package/build/legacy/types.js +0 -12
- package/build/legacy/types.js.map +0 -1
- package/build/legacy/utils.cjs +0 -330
- package/build/legacy/utils.cjs.map +0 -1
- package/build/legacy/utils.d.cts +0 -30
- package/build/legacy/utils.d.ts +0 -30
- package/build/legacy/utils.js +0 -283
- package/build/legacy/utils.js.map +0 -1
- package/build/modern/_tsup-dts-rollup.d.cts +0 -2229
- package/build/modern/_tsup-dts-rollup.d.ts +0 -2229
- package/build/modern/environmentManager.cjs +0 -48
- package/build/modern/environmentManager.cjs.map +0 -1
- package/build/modern/environmentManager.d.cts +0 -2
- package/build/modern/environmentManager.d.ts +0 -2
- package/build/modern/environmentManager.js +0 -23
- package/build/modern/environmentManager.js.map +0 -1
- package/build/modern/focusManager.cjs +0 -93
- package/build/modern/focusManager.cjs.map +0 -1
- package/build/modern/focusManager.d.cts +0 -2
- package/build/modern/focusManager.d.ts +0 -2
- package/build/modern/focusManager.js +0 -67
- package/build/modern/focusManager.js.map +0 -1
- package/build/modern/hydration.cjs +0 -173
- package/build/modern/hydration.cjs.map +0 -1
- package/build/modern/hydration.d.cts +0 -7
- package/build/modern/hydration.d.ts +0 -7
- package/build/modern/hydration.js +0 -145
- package/build/modern/hydration.js.map +0 -1
- package/build/modern/index.cjs +0 -113
- package/build/modern/index.cjs.map +0 -1
- package/build/modern/index.d.cts +0 -142
- package/build/modern/index.d.ts +0 -142
- package/build/modern/index.js +0 -73
- package/build/modern/index.js.map +0 -1
- package/build/modern/infiniteQueryBehavior.cjs +0 -142
- package/build/modern/infiniteQueryBehavior.cjs.map +0 -1
- package/build/modern/infiniteQueryBehavior.d.cts +0 -3
- package/build/modern/infiniteQueryBehavior.d.ts +0 -3
- package/build/modern/infiniteQueryBehavior.js +0 -120
- package/build/modern/infiniteQueryBehavior.js.map +0 -1
- package/build/modern/infiniteQueryObserver.cjs +0 -92
- package/build/modern/infiniteQueryObserver.cjs.map +0 -1
- package/build/modern/infiniteQueryObserver.d.cts +0 -1
- package/build/modern/infiniteQueryObserver.d.ts +0 -1
- package/build/modern/infiniteQueryObserver.js +0 -71
- package/build/modern/infiniteQueryObserver.js.map +0 -1
- package/build/modern/mutation.cjs +0 -307
- package/build/modern/mutation.cjs.map +0 -1
- package/build/modern/mutation.d.cts +0 -4
- package/build/modern/mutation.d.ts +0 -4
- package/build/modern/mutation.js +0 -281
- package/build/modern/mutation.js.map +0 -1
- package/build/modern/mutationCache.cjs +0 -149
- package/build/modern/mutationCache.cjs.map +0 -1
- package/build/modern/mutationCache.d.cts +0 -2
- package/build/modern/mutationCache.d.ts +0 -2
- package/build/modern/mutationCache.js +0 -124
- package/build/modern/mutationCache.js.map +0 -1
- package/build/modern/mutationObserver.cjs +0 -165
- package/build/modern/mutationObserver.cjs.map +0 -1
- package/build/modern/mutationObserver.d.cts +0 -1
- package/build/modern/mutationObserver.d.ts +0 -1
- package/build/modern/mutationObserver.js +0 -140
- package/build/modern/mutationObserver.js.map +0 -1
- package/build/modern/notifyManager.cjs +0 -113
- package/build/modern/notifyManager.cjs.map +0 -1
- package/build/modern/notifyManager.d.cts +0 -3
- package/build/modern/notifyManager.d.ts +0 -3
- package/build/modern/notifyManager.js +0 -86
- package/build/modern/notifyManager.js.map +0 -1
- package/build/modern/onlineManager.cjs +0 -83
- package/build/modern/onlineManager.cjs.map +0 -1
- package/build/modern/onlineManager.d.cts +0 -2
- package/build/modern/onlineManager.d.ts +0 -2
- package/build/modern/onlineManager.js +0 -57
- package/build/modern/onlineManager.js.map +0 -1
- package/build/modern/queriesObserver.cjs +0 -237
- package/build/modern/queriesObserver.cjs.map +0 -1
- package/build/modern/queriesObserver.d.cts +0 -2
- package/build/modern/queriesObserver.d.ts +0 -2
- package/build/modern/queriesObserver.js +0 -212
- package/build/modern/queriesObserver.js.map +0 -1
- package/build/modern/query.cjs +0 -461
- package/build/modern/query.cjs.map +0 -1
- package/build/modern/query.d.cts +0 -10
- package/build/modern/query.d.ts +0 -10
- package/build/modern/query.js +0 -443
- package/build/modern/query.js.map +0 -1
- package/build/modern/queryCache.cjs +0 -122
- package/build/modern/queryCache.cjs.map +0 -1
- package/build/modern/queryCache.d.cts +0 -3
- package/build/modern/queryCache.d.ts +0 -3
- package/build/modern/queryCache.js +0 -97
- package/build/modern/queryCache.js.map +0 -1
- package/build/modern/queryClient.cjs +0 -322
- package/build/modern/queryClient.cjs.map +0 -1
- package/build/modern/queryClient.d.cts +0 -1
- package/build/modern/queryClient.d.ts +0 -1
- package/build/modern/queryClient.js +0 -305
- package/build/modern/queryClient.js.map +0 -1
- package/build/modern/queryObserver.cjs +0 -489
- package/build/modern/queryObserver.cjs.map +0 -1
- package/build/modern/queryObserver.d.cts +0 -1
- package/build/modern/queryObserver.d.ts +0 -1
- package/build/modern/queryObserver.js +0 -472
- package/build/modern/queryObserver.js.map +0 -1
- package/build/modern/removable.cjs +0 -59
- package/build/modern/removable.cjs.map +0 -1
- package/build/modern/removable.d.cts +0 -1
- package/build/modern/removable.d.ts +0 -1
- package/build/modern/removable.js +0 -34
- package/build/modern/removable.js.map +0 -1
- package/build/modern/retryer.cjs +0 -162
- package/build/modern/retryer.cjs.map +0 -1
- package/build/modern/retryer.d.cts +0 -7
- package/build/modern/retryer.d.ts +0 -7
- package/build/modern/retryer.js +0 -134
- package/build/modern/retryer.js.map +0 -1
- package/build/modern/streamedQuery.cjs +0 -80
- package/build/modern/streamedQuery.cjs.map +0 -1
- package/build/modern/streamedQuery.d.cts +0 -1
- package/build/modern/streamedQuery.d.ts +0 -1
- package/build/modern/streamedQuery.js +0 -55
- package/build/modern/streamedQuery.js.map +0 -1
- package/build/modern/subscribable.cjs +0 -51
- package/build/modern/subscribable.cjs.map +0 -1
- package/build/modern/subscribable.d.cts +0 -1
- package/build/modern/subscribable.d.ts +0 -1
- package/build/modern/subscribable.js +0 -26
- package/build/modern/subscribable.js.map +0 -1
- package/build/modern/thenable.cjs +0 -75
- package/build/modern/thenable.cjs.map +0 -1
- package/build/modern/thenable.d.cts +0 -6
- package/build/modern/thenable.d.ts +0 -6
- package/build/modern/thenable.js +0 -49
- package/build/modern/thenable.js.map +0 -1
- package/build/modern/timeoutManager.cjs +0 -98
- package/build/modern/timeoutManager.cjs.map +0 -1
- package/build/modern/timeoutManager.d.cts +0 -7
- package/build/modern/timeoutManager.d.ts +0 -7
- package/build/modern/timeoutManager.js +0 -70
- package/build/modern/timeoutManager.js.map +0 -1
- package/build/modern/types.cjs +0 -37
- package/build/modern/types.cjs.map +0 -1
- package/build/modern/types.d.cts +0 -95
- package/build/modern/types.d.ts +0 -95
- package/build/modern/types.js +0 -10
- package/build/modern/types.js.map +0 -1
- package/build/modern/utils.cjs +0 -330
- package/build/modern/utils.cjs.map +0 -1
- package/build/modern/utils.d.cts +0 -30
- package/build/modern/utils.d.ts +0 -30
- package/build/modern/utils.js +0 -281
- package/build/modern/utils.js.map +0 -1
package/build/modern/retryer.cjs
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/retryer.ts
|
|
21
|
-
var retryer_exports = {};
|
|
22
|
-
__export(retryer_exports, {
|
|
23
|
-
CancelledError: () => CancelledError,
|
|
24
|
-
canFetch: () => canFetch,
|
|
25
|
-
createRetryer: () => createRetryer,
|
|
26
|
-
isCancelledError: () => isCancelledError
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(retryer_exports);
|
|
29
|
-
var import_focusManager = require("./focusManager.cjs");
|
|
30
|
-
var import_onlineManager = require("./onlineManager.cjs");
|
|
31
|
-
var import_thenable = require("./thenable.cjs");
|
|
32
|
-
var import_environmentManager = require("./environmentManager.cjs");
|
|
33
|
-
var import_utils = require("./utils.cjs");
|
|
34
|
-
function defaultRetryDelay(failureCount) {
|
|
35
|
-
return Math.min(1e3 * 2 ** failureCount, 3e4);
|
|
36
|
-
}
|
|
37
|
-
function canFetch(networkMode) {
|
|
38
|
-
return (networkMode ?? "online") === "online" ? import_onlineManager.onlineManager.isOnline() : true;
|
|
39
|
-
}
|
|
40
|
-
var CancelledError = class extends Error {
|
|
41
|
-
constructor(options) {
|
|
42
|
-
super("CancelledError");
|
|
43
|
-
this.revert = options?.revert;
|
|
44
|
-
this.silent = options?.silent;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function isCancelledError(value) {
|
|
48
|
-
return value instanceof CancelledError;
|
|
49
|
-
}
|
|
50
|
-
function createRetryer(config) {
|
|
51
|
-
let isRetryCancelled = false;
|
|
52
|
-
let failureCount = 0;
|
|
53
|
-
let continueFn;
|
|
54
|
-
const thenable = (0, import_thenable.pendingThenable)();
|
|
55
|
-
const isResolved = () => thenable.status !== "pending";
|
|
56
|
-
const cancel = (cancelOptions) => {
|
|
57
|
-
if (!isResolved()) {
|
|
58
|
-
const error = new CancelledError(cancelOptions);
|
|
59
|
-
reject(error);
|
|
60
|
-
config.onCancel?.(error);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const cancelRetry = () => {
|
|
64
|
-
isRetryCancelled = true;
|
|
65
|
-
};
|
|
66
|
-
const continueRetry = () => {
|
|
67
|
-
isRetryCancelled = false;
|
|
68
|
-
};
|
|
69
|
-
const canContinue = () => import_focusManager.focusManager.isFocused() && (config.networkMode === "always" || import_onlineManager.onlineManager.isOnline()) && config.canRun();
|
|
70
|
-
const canStart = () => canFetch(config.networkMode) && config.canRun();
|
|
71
|
-
const resolve = (value) => {
|
|
72
|
-
if (!isResolved()) {
|
|
73
|
-
continueFn?.();
|
|
74
|
-
thenable.resolve(value);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const reject = (value) => {
|
|
78
|
-
if (!isResolved()) {
|
|
79
|
-
continueFn?.();
|
|
80
|
-
thenable.reject(value);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const pause = () => {
|
|
84
|
-
return new Promise((continueResolve) => {
|
|
85
|
-
continueFn = (value) => {
|
|
86
|
-
if (isResolved() || canContinue()) {
|
|
87
|
-
continueResolve(value);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
config.onPause?.();
|
|
91
|
-
}).then(() => {
|
|
92
|
-
continueFn = void 0;
|
|
93
|
-
if (!isResolved()) {
|
|
94
|
-
config.onContinue?.();
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
const run = () => {
|
|
99
|
-
if (isResolved()) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
let promiseOrValue;
|
|
103
|
-
const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
|
|
104
|
-
try {
|
|
105
|
-
promiseOrValue = initialPromise ?? config.fn();
|
|
106
|
-
} catch (error) {
|
|
107
|
-
promiseOrValue = Promise.reject(error);
|
|
108
|
-
}
|
|
109
|
-
Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
|
|
110
|
-
if (isResolved()) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const retry = config.retry ?? (import_environmentManager.environmentManager.isServer() ? 0 : 3);
|
|
114
|
-
const retryDelay = config.retryDelay ?? defaultRetryDelay;
|
|
115
|
-
const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
|
|
116
|
-
const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
|
|
117
|
-
if (isRetryCancelled || !shouldRetry) {
|
|
118
|
-
reject(error);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
failureCount++;
|
|
122
|
-
config.onFail?.(failureCount, error);
|
|
123
|
-
(0, import_utils.sleep)(delay).then(() => {
|
|
124
|
-
return canContinue() ? void 0 : pause();
|
|
125
|
-
}).then(() => {
|
|
126
|
-
if (isRetryCancelled) {
|
|
127
|
-
reject(error);
|
|
128
|
-
} else {
|
|
129
|
-
run();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
return {
|
|
135
|
-
promise: thenable,
|
|
136
|
-
status: () => thenable.status,
|
|
137
|
-
cancel,
|
|
138
|
-
continue: () => {
|
|
139
|
-
continueFn?.();
|
|
140
|
-
return thenable;
|
|
141
|
-
},
|
|
142
|
-
cancelRetry,
|
|
143
|
-
continueRetry,
|
|
144
|
-
canStart,
|
|
145
|
-
start: () => {
|
|
146
|
-
if (canStart()) {
|
|
147
|
-
run();
|
|
148
|
-
} else {
|
|
149
|
-
pause().then(run);
|
|
150
|
-
}
|
|
151
|
-
return thenable;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
-
0 && (module.exports = {
|
|
157
|
-
CancelledError,
|
|
158
|
-
canFetch,
|
|
159
|
-
createRetryer,
|
|
160
|
-
isCancelledError
|
|
161
|
-
});
|
|
162
|
-
//# sourceMappingURL=retryer.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/retryer.ts"],"sourcesContent":["import { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { pendingThenable } from './thenable'\nimport { environmentManager } from './environmentManager'\nimport { sleep } from './utils'\nimport type { Thenable } from './thenable'\nimport type { CancelOptions, DefaultError, NetworkMode } from './types'\n\n// TYPES\n\ninterface RetryerConfig<TData = unknown, TError = DefaultError> {\n fn: () => TData | Promise<TData>\n initialPromise?: Promise<TData>\n onCancel?: (error: TError) => void\n onFail?: (failureCount: number, error: TError) => void\n onPause?: () => void\n onContinue?: () => void\n retry?: RetryValue<TError>\n retryDelay?: RetryDelayValue<TError>\n networkMode: NetworkMode | undefined\n canRun: () => boolean\n}\n\nexport interface Retryer<TData = unknown> {\n promise: Promise<TData>\n cancel: (cancelOptions?: CancelOptions) => void\n continue: () => Promise<unknown>\n cancelRetry: () => void\n continueRetry: () => void\n canStart: () => boolean\n start: () => Promise<TData>\n status: () => 'pending' | 'resolved' | 'rejected'\n}\n\nexport type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>\n\ntype ShouldRetryFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => boolean\n\nexport type RetryDelayValue<TError> = number | RetryDelayFunction<TError>\n\ntype RetryDelayFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => number\n\nfunction defaultRetryDelay(failureCount: number) {\n return Math.min(1000 * 2 ** failureCount, 30000)\n}\n\nexport function canFetch(networkMode: NetworkMode | undefined): boolean {\n return (networkMode ?? 'online') === 'online'\n ? onlineManager.isOnline()\n : true\n}\n\nexport class CancelledError extends Error {\n revert?: boolean\n silent?: boolean\n constructor(options?: CancelOptions) {\n super('CancelledError')\n this.revert = options?.revert\n this.silent = options?.silent\n }\n}\n\n/**\n * @deprecated Use instanceof `CancelledError` instead.\n */\nexport function isCancelledError(value: any): value is CancelledError {\n return value instanceof CancelledError\n}\n\nexport function createRetryer<TData = unknown, TError = DefaultError>(\n config: RetryerConfig<TData, TError>,\n): Retryer<TData> {\n let isRetryCancelled = false\n let failureCount = 0\n let continueFn: ((value?: unknown) => void) | undefined\n\n const thenable = pendingThenable<TData>()\n\n const isResolved = () =>\n (thenable.status as Thenable<TData>['status']) !== 'pending'\n\n const cancel = (cancelOptions?: CancelOptions): void => {\n if (!isResolved()) {\n const error = new CancelledError(cancelOptions) as TError\n reject(error)\n\n config.onCancel?.(error)\n }\n }\n const cancelRetry = () => {\n isRetryCancelled = true\n }\n\n const continueRetry = () => {\n isRetryCancelled = false\n }\n\n const canContinue = () =>\n focusManager.isFocused() &&\n (config.networkMode === 'always' || onlineManager.isOnline()) &&\n config.canRun()\n\n const canStart = () => canFetch(config.networkMode) && config.canRun()\n\n const resolve = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n thenable.resolve(value)\n }\n }\n\n const reject = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n thenable.reject(value)\n }\n }\n\n const pause = () => {\n return new Promise((continueResolve) => {\n continueFn = (value) => {\n if (isResolved() || canContinue()) {\n continueResolve(value)\n }\n }\n config.onPause?.()\n }).then(() => {\n continueFn = undefined\n if (!isResolved()) {\n config.onContinue?.()\n }\n })\n }\n\n // Create loop function\n const run = () => {\n // Do nothing if already resolved\n if (isResolved()) {\n return\n }\n\n let promiseOrValue: any\n\n // we can re-use config.initialPromise on the first call of run()\n const initialPromise =\n failureCount === 0 ? config.initialPromise : undefined\n\n // Execute query\n try {\n promiseOrValue = initialPromise ?? config.fn()\n } catch (error) {\n promiseOrValue = Promise.reject(error)\n }\n\n Promise.resolve(promiseOrValue)\n .then(resolve)\n .catch((error) => {\n // Stop if the fetch is already resolved\n if (isResolved()) {\n return\n }\n\n // Do we need to retry the request?\n const retry = config.retry ?? (environmentManager.isServer() ? 0 : 3)\n const retryDelay = config.retryDelay ?? defaultRetryDelay\n const delay =\n typeof retryDelay === 'function'\n ? retryDelay(failureCount, error)\n : retryDelay\n const shouldRetry =\n retry === true ||\n (typeof retry === 'number' && failureCount < retry) ||\n (typeof retry === 'function' && retry(failureCount, error))\n\n if (isRetryCancelled || !shouldRetry) {\n // We are done if the query does not need to be retried\n reject(error)\n return\n }\n\n failureCount++\n\n // Notify on fail\n config.onFail?.(failureCount, error)\n\n // Delay\n sleep(delay)\n // Pause if the document is not visible or when the device is offline\n .then(() => {\n return canContinue() ? undefined : pause()\n })\n .then(() => {\n if (isRetryCancelled) {\n reject(error)\n } else {\n run()\n }\n })\n })\n }\n\n return {\n promise: thenable,\n status: () => thenable.status,\n cancel,\n continue: () => {\n continueFn?.()\n return thenable\n },\n cancelRetry,\n continueRetry,\n canStart,\n start: () => {\n // Start loop\n if (canStart()) {\n run()\n } else {\n pause().then(run)\n }\n return thenable\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAC7B,2BAA8B;AAC9B,sBAAgC;AAChC,gCAAmC;AACnC,mBAAsB;AA4CtB,SAAS,kBAAkB,cAAsB;AAC/C,SAAO,KAAK,IAAI,MAAO,KAAK,cAAc,GAAK;AACjD;AAEO,SAAS,SAAS,aAA+C;AACtE,UAAQ,eAAe,cAAc,WACjC,mCAAc,SAAS,IACvB;AACN;AAEO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAGxC,YAAY,SAAyB;AACnC,UAAM,gBA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ClB;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { canFetch } from './_tsup-dts-rollup.cjs';
|
|
2
|
-
export { isCancelledError_alias_1 as isCancelledError } from './_tsup-dts-rollup.cjs';
|
|
3
|
-
export { createRetryer } from './_tsup-dts-rollup.cjs';
|
|
4
|
-
export { Retryer } from './_tsup-dts-rollup.cjs';
|
|
5
|
-
export { RetryValue } from './_tsup-dts-rollup.cjs';
|
|
6
|
-
export { RetryDelayValue } from './_tsup-dts-rollup.cjs';
|
|
7
|
-
export { CancelledError_alias_1 as CancelledError } from './_tsup-dts-rollup.cjs';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { canFetch } from './_tsup-dts-rollup.js';
|
|
2
|
-
export { isCancelledError_alias_1 as isCancelledError } from './_tsup-dts-rollup.js';
|
|
3
|
-
export { createRetryer } from './_tsup-dts-rollup.js';
|
|
4
|
-
export { Retryer } from './_tsup-dts-rollup.js';
|
|
5
|
-
export { RetryValue } from './_tsup-dts-rollup.js';
|
|
6
|
-
export { RetryDelayValue } from './_tsup-dts-rollup.js';
|
|
7
|
-
export { CancelledError_alias_1 as CancelledError } from './_tsup-dts-rollup.js';
|
package/build/modern/retryer.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// src/retryer.ts
|
|
2
|
-
import { focusManager } from "./focusManager.js";
|
|
3
|
-
import { onlineManager } from "./onlineManager.js";
|
|
4
|
-
import { pendingThenable } from "./thenable.js";
|
|
5
|
-
import { environmentManager } from "./environmentManager.js";
|
|
6
|
-
import { sleep } from "./utils.js";
|
|
7
|
-
function defaultRetryDelay(failureCount) {
|
|
8
|
-
return Math.min(1e3 * 2 ** failureCount, 3e4);
|
|
9
|
-
}
|
|
10
|
-
function canFetch(networkMode) {
|
|
11
|
-
return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
|
|
12
|
-
}
|
|
13
|
-
var CancelledError = class extends Error {
|
|
14
|
-
constructor(options) {
|
|
15
|
-
super("CancelledError");
|
|
16
|
-
this.revert = options?.revert;
|
|
17
|
-
this.silent = options?.silent;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
function isCancelledError(value) {
|
|
21
|
-
return value instanceof CancelledError;
|
|
22
|
-
}
|
|
23
|
-
function createRetryer(config) {
|
|
24
|
-
let isRetryCancelled = false;
|
|
25
|
-
let failureCount = 0;
|
|
26
|
-
let continueFn;
|
|
27
|
-
const thenable = pendingThenable();
|
|
28
|
-
const isResolved = () => thenable.status !== "pending";
|
|
29
|
-
const cancel = (cancelOptions) => {
|
|
30
|
-
if (!isResolved()) {
|
|
31
|
-
const error = new CancelledError(cancelOptions);
|
|
32
|
-
reject(error);
|
|
33
|
-
config.onCancel?.(error);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const cancelRetry = () => {
|
|
37
|
-
isRetryCancelled = true;
|
|
38
|
-
};
|
|
39
|
-
const continueRetry = () => {
|
|
40
|
-
isRetryCancelled = false;
|
|
41
|
-
};
|
|
42
|
-
const canContinue = () => focusManager.isFocused() && (config.networkMode === "always" || onlineManager.isOnline()) && config.canRun();
|
|
43
|
-
const canStart = () => canFetch(config.networkMode) && config.canRun();
|
|
44
|
-
const resolve = (value) => {
|
|
45
|
-
if (!isResolved()) {
|
|
46
|
-
continueFn?.();
|
|
47
|
-
thenable.resolve(value);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const reject = (value) => {
|
|
51
|
-
if (!isResolved()) {
|
|
52
|
-
continueFn?.();
|
|
53
|
-
thenable.reject(value);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const pause = () => {
|
|
57
|
-
return new Promise((continueResolve) => {
|
|
58
|
-
continueFn = (value) => {
|
|
59
|
-
if (isResolved() || canContinue()) {
|
|
60
|
-
continueResolve(value);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
config.onPause?.();
|
|
64
|
-
}).then(() => {
|
|
65
|
-
continueFn = void 0;
|
|
66
|
-
if (!isResolved()) {
|
|
67
|
-
config.onContinue?.();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
const run = () => {
|
|
72
|
-
if (isResolved()) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
let promiseOrValue;
|
|
76
|
-
const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
|
|
77
|
-
try {
|
|
78
|
-
promiseOrValue = initialPromise ?? config.fn();
|
|
79
|
-
} catch (error) {
|
|
80
|
-
promiseOrValue = Promise.reject(error);
|
|
81
|
-
}
|
|
82
|
-
Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
|
|
83
|
-
if (isResolved()) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const retry = config.retry ?? (environmentManager.isServer() ? 0 : 3);
|
|
87
|
-
const retryDelay = config.retryDelay ?? defaultRetryDelay;
|
|
88
|
-
const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
|
|
89
|
-
const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
|
|
90
|
-
if (isRetryCancelled || !shouldRetry) {
|
|
91
|
-
reject(error);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
failureCount++;
|
|
95
|
-
config.onFail?.(failureCount, error);
|
|
96
|
-
sleep(delay).then(() => {
|
|
97
|
-
return canContinue() ? void 0 : pause();
|
|
98
|
-
}).then(() => {
|
|
99
|
-
if (isRetryCancelled) {
|
|
100
|
-
reject(error);
|
|
101
|
-
} else {
|
|
102
|
-
run();
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
promise: thenable,
|
|
109
|
-
status: () => thenable.status,
|
|
110
|
-
cancel,
|
|
111
|
-
continue: () => {
|
|
112
|
-
continueFn?.();
|
|
113
|
-
return thenable;
|
|
114
|
-
},
|
|
115
|
-
cancelRetry,
|
|
116
|
-
continueRetry,
|
|
117
|
-
canStart,
|
|
118
|
-
start: () => {
|
|
119
|
-
if (canStart()) {
|
|
120
|
-
run();
|
|
121
|
-
} else {
|
|
122
|
-
pause().then(run);
|
|
123
|
-
}
|
|
124
|
-
return thenable;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
export {
|
|
129
|
-
CancelledError,
|
|
130
|
-
canFetch,
|
|
131
|
-
createRetryer,
|
|
132
|
-
isCancelledError
|
|
133
|
-
};
|
|
134
|
-
//# sourceMappingURL=retryer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/retryer.ts"],"sourcesContent":["import { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { pendingThenable } from './thenable'\nimport { environmentManager } from './environmentManager'\nimport { sleep } from './utils'\nimport type { Thenable } from './thenable'\nimport type { CancelOptions, DefaultError, NetworkMode } from './types'\n\n// TYPES\n\ninterface RetryerConfig<TData = unknown, TError = DefaultError> {\n fn: () => TData | Promise<TData>\n initialPromise?: Promise<TData>\n onCancel?: (error: TError) => void\n onFail?: (failureCount: number, error: TError) => void\n onPause?: () => void\n onContinue?: () => void\n retry?: RetryValue<TError>\n retryDelay?: RetryDelayValue<TError>\n networkMode: NetworkMode | undefined\n canRun: () => boolean\n}\n\nexport interface Retryer<TData = unknown> {\n promise: Promise<TData>\n cancel: (cancelOptions?: CancelOptions) => void\n continue: () => Promise<unknown>\n cancelRetry: () => void\n continueRetry: () => void\n canStart: () => boolean\n start: () => Promise<TData>\n status: () => 'pending' | 'resolved' | 'rejected'\n}\n\nexport type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>\n\ntype ShouldRetryFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => boolean\n\nexport type RetryDelayValue<TError> = number | RetryDelayFunction<TError>\n\ntype RetryDelayFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => number\n\nfunction defaultRetryDelay(failureCount: number) {\n return Math.min(1000 * 2 ** failureCount, 30000)\n}\n\nexport function canFetch(networkMode: NetworkMode | undefined): boolean {\n return (networkMode ?? 'online') === 'online'\n ? onlineManager.isOnline()\n : true\n}\n\nexport class CancelledError extends Error {\n revert?: boolean\n silent?: boolean\n constructor(options?: CancelOptions) {\n super('CancelledError')\n this.revert = options?.revert\n this.silent = options?.silent\n }\n}\n\n/**\n * @deprecated Use instanceof `CancelledError` instead.\n */\nexport function isCancelledError(value: any): value is CancelledError {\n return value instanceof CancelledError\n}\n\nexport function createRetryer<TData = unknown, TError = DefaultError>(\n config: RetryerConfig<TData, TError>,\n): Retryer<TData> {\n let isRetryCancelled = false\n let failureCount = 0\n let continueFn: ((value?: unknown) => void) | undefined\n\n const thenable = pendingThenable<TData>()\n\n const isResolved = () =>\n (thenable.status as Thenable<TData>['status']) !== 'pending'\n\n const cancel = (cancelOptions?: CancelOptions): void => {\n if (!isResolved()) {\n const error = new CancelledError(cancelOptions) as TError\n reject(error)\n\n config.onCancel?.(error)\n }\n }\n const cancelRetry = () => {\n isRetryCancelled = true\n }\n\n const continueRetry = () => {\n isRetryCancelled = false\n }\n\n const canContinue = () =>\n focusManager.isFocused() &&\n (config.networkMode === 'always' || onlineManager.isOnline()) &&\n config.canRun()\n\n const canStart = () => canFetch(config.networkMode) && config.canRun()\n\n const resolve = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n thenable.resolve(value)\n }\n }\n\n const reject = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n thenable.reject(value)\n }\n }\n\n const pause = () => {\n return new Promise((continueResolve) => {\n continueFn = (value) => {\n if (isResolved() || canContinue()) {\n continueResolve(value)\n }\n }\n config.onPause?.()\n }).then(() => {\n continueFn = undefined\n if (!isResolved()) {\n config.onContinue?.()\n }\n })\n }\n\n // Create loop function\n const run = () => {\n // Do nothing if already resolved\n if (isResolved()) {\n return\n }\n\n let promiseOrValue: any\n\n // we can re-use config.initialPromise on the first call of run()\n const initialPromise =\n failureCount === 0 ? config.initialPromise : undefined\n\n // Execute query\n try {\n promiseOrValue = initialPromise ?? config.fn()\n } catch (error) {\n promiseOrValue = Promise.reject(error)\n }\n\n Promise.resolve(promiseOrValue)\n .then(resolve)\n .catch((error) => {\n // Stop if the fetch is already resolved\n if (isResolved()) {\n return\n }\n\n // Do we need to retry the request?\n const retry = config.retry ?? (environmentManager.isServer() ? 0 : 3)\n const retryDelay = config.retryDelay ?? defaultRetryDelay\n const delay =\n typeof retryDelay === 'function'\n ? retryDelay(failureCount, error)\n : retryDelay\n const shouldRetry =\n retry === true ||\n (typeof retry === 'number' && failureCount < retry) ||\n (typeof retry === 'function' && retry(failureCount, error))\n\n if (isRetryCancelled || !shouldRetry) {\n // We are done if the query does not need to be retried\n reject(error)\n return\n }\n\n failureCount++\n\n // Notify on fail\n config.onFail?.(failureCount, error)\n\n // Delay\n sleep(delay)\n // Pause if the document is not visible or when the device is offline\n .then(() => {\n return canContinue() ? undefined : pause()\n })\n .then(() => {\n if (isRetryCancelled) {\n reject(error)\n } else {\n run()\n }\n })\n })\n }\n\n return {\n promise: thenable,\n status: () => thenable.status,\n cancel,\n continue: () => {\n continueFn?.()\n return thenable\n },\n cancelRetry,\n continueRetry,\n canStart,\n start: () => {\n // Start loop\n if (canStart()) {\n run()\n } else {\n pause().then(run)\n }\n return thenable\n },\n }\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,aAAa;AA4CtB,SAAS,kBAAkB,cAAsB;AAC/C,SAAO,KAAK,IAAI,MAAO,KAAK,cAAc,GAAK;AACjD;AAEO,SAAS,SAAS,aAA+C;AACtE,UAAQ,eAAe,cAAc,WACjC,cAAc,SAAS,IACvB;AACN;AAEO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAGxC,YAAY,SAAyB;AACnC,UAAM,gBAAgB;AACtB,SAAK,SAAS,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AAA,EACF;AACF;","names":[]}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/streamedQuery.ts
|
|
21
|
-
var streamedQuery_exports = {};
|
|
22
|
-
__export(streamedQuery_exports, {
|
|
23
|
-
streamedQuery: () => streamedQuery
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(streamedQuery_exports);
|
|
26
|
-
var import_utils = require("./utils.cjs");
|
|
27
|
-
function streamedQuery({
|
|
28
|
-
streamFn,
|
|
29
|
-
refetchMode = "reset",
|
|
30
|
-
reducer = (items, chunk) => (0, import_utils.addToEnd)(items, chunk),
|
|
31
|
-
initialValue = []
|
|
32
|
-
}) {
|
|
33
|
-
return async (context) => {
|
|
34
|
-
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
35
|
-
const isRefetch = !!query && query.isFetched();
|
|
36
|
-
if (isRefetch && refetchMode === "reset") {
|
|
37
|
-
query.setState({
|
|
38
|
-
...query.resetState,
|
|
39
|
-
fetchStatus: "fetching"
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
let result = initialValue;
|
|
43
|
-
let cancelled = false;
|
|
44
|
-
const streamFnContext = (0, import_utils.addConsumeAwareSignal)(
|
|
45
|
-
{
|
|
46
|
-
client: context.client,
|
|
47
|
-
meta: context.meta,
|
|
48
|
-
queryKey: context.queryKey,
|
|
49
|
-
pageParam: context.pageParam,
|
|
50
|
-
direction: context.direction
|
|
51
|
-
},
|
|
52
|
-
() => context.signal,
|
|
53
|
-
() => cancelled = true
|
|
54
|
-
);
|
|
55
|
-
const stream = await streamFn(streamFnContext);
|
|
56
|
-
const isReplaceRefetch = isRefetch && refetchMode === "replace";
|
|
57
|
-
for await (const chunk of stream) {
|
|
58
|
-
if (cancelled) {
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
if (isReplaceRefetch) {
|
|
62
|
-
result = reducer(result, chunk);
|
|
63
|
-
} else {
|
|
64
|
-
context.client.setQueryData(
|
|
65
|
-
context.queryKey,
|
|
66
|
-
(prev) => reducer(prev === void 0 ? initialValue : prev, chunk)
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (isReplaceRefetch && !cancelled) {
|
|
71
|
-
context.client.setQueryData(context.queryKey, result);
|
|
72
|
-
}
|
|
73
|
-
return context.client.getQueryData(context.queryKey) ?? initialValue;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
-
0 && (module.exports = {
|
|
78
|
-
streamedQuery
|
|
79
|
-
});
|
|
80
|
-
//# sourceMappingURL=streamedQuery.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defines how re-fetches are handled.\n * Defaults to `'reset'`, erases all data and puts the query back into `pending` state.\n * Set to `'append'` to append new data to the existing data.\n * Set to `'replace'` to write all data to the cache once the stream ends.\n * @param reducer - A function to reduce the streamed chunks into the final data.\n * Defaults to a function that appends chunks to the end of the array.\n * @param initialValue - Initial value to be used while the first chunk is being fetched, and returned if the stream yields no values.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TData = Array<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n>({\n streamFn,\n refetchMode = 'reset',\n reducer = (items, chunk) =>\n addToEnd(items as Array<TQueryFnData>, chunk) as TData,\n initialValue = [] as TData,\n}: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<\n TData,\n TQueryKey\n> {\n return async (context) => {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n const isRefetch = !!query && query.isFetched()\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n ...query.resetState,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n let cancelled: boolean = false as boolean\n const streamFnContext = addConsumeAwareSignal<\n OmitKeyof<typeof context, 'signal'>\n >(\n {\n client: context.client,\n meta: context.meta,\n queryKey: context.queryKey,\n pageParam: context.pageParam,\n direction: context.direction,\n },\n () => context.signal,\n () => (cancelled = true),\n )\n\n const stream = await streamFn(streamFnContext)\n\n const isReplaceRefetch = isRefetch && refetchMode === 'replace'\n\n for await (const chunk of stream) {\n if (cancelled) {\n break\n }\n\n if (isReplaceRefetch) {\n // don't append to the cache directly when replace-refetching\n result = reducer(result, chunk)\n } else {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isReplaceRefetch && !cancelled) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n return context.client.getQueryData(context.queryKey) ?? initialValue\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgD;AAkDzC,SAAS,cAId;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,UAAU,CAAC,OAAO,cAChB,uBAAS,OAA8B,KAAK;AAAA,EAC9C,eAAe,CAAC;AAClB,GAGE;AACA,SAAO,OAAO,YAAY;AACxB,UAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAM,YAAY,CAAC,CAAC,SAAS,MAAM,UAAU;AAC7C,QAAI,aAAa,gBAAgB,SAAS;AACxC,YAAM,SAAS;AAAA,QACb,GAAG,MAAM;AAAA,QACT,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAEA,QAAI,SAAS;AAEb,QAAI,YAAqB;AACzB,UAAM,sBAAkB;AAAA,MAGtB;AAAA,QACE,QAAQ,QAAQ;AAAA,QAChB,MAAM,QAAQ;AAAA,QACd,UAAU,QAAQ;AAAA,QAClB,WAAW,QAAQ;AAAA,QACnB,WAAW,QAAQ;AAAA,MACrB;AAAA,MACA,MAAM,QAAQ;AAAA,MACd,MAAO,YAAY;AAAA,IACrB;AAEA,UAAM,SAAS,MAAM,SAAS,eAAe;AAE7C,UAAM,mBAAmB,aAAa,gBAAgB;AAEtD,qBAAiB,SAAS,QAAQ;AAChC,UAAI,WAAW;AACb;AAAA,MACF;AAEA,UAAI,kBAAkB;AAEpB,iBAAS,QAAQ,QAAQ,KAAK;AAAA,MAChC,OAAO;AACL,gBAAQ,OAAO;AAAA,UAAoB,QAAQ;AAAA,UAAU,CAAC,SACpD,QAAQ,SAAS,SAAY,eAAe,MAAM,KAAK;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAGA,QAAI,oBAAoB,CAAC,WAAW;AAClC,cAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;AAAA,IAC7D;AAEA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ,KAAK;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { streamedQuery } from './_tsup-dts-rollup.cjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { streamedQuery } from './_tsup-dts-rollup.js';
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// src/streamedQuery.ts
|
|
2
|
-
import { addConsumeAwareSignal, addToEnd } from "./utils.js";
|
|
3
|
-
function streamedQuery({
|
|
4
|
-
streamFn,
|
|
5
|
-
refetchMode = "reset",
|
|
6
|
-
reducer = (items, chunk) => addToEnd(items, chunk),
|
|
7
|
-
initialValue = []
|
|
8
|
-
}) {
|
|
9
|
-
return async (context) => {
|
|
10
|
-
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
11
|
-
const isRefetch = !!query && query.isFetched();
|
|
12
|
-
if (isRefetch && refetchMode === "reset") {
|
|
13
|
-
query.setState({
|
|
14
|
-
...query.resetState,
|
|
15
|
-
fetchStatus: "fetching"
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
let result = initialValue;
|
|
19
|
-
let cancelled = false;
|
|
20
|
-
const streamFnContext = addConsumeAwareSignal(
|
|
21
|
-
{
|
|
22
|
-
client: context.client,
|
|
23
|
-
meta: context.meta,
|
|
24
|
-
queryKey: context.queryKey,
|
|
25
|
-
pageParam: context.pageParam,
|
|
26
|
-
direction: context.direction
|
|
27
|
-
},
|
|
28
|
-
() => context.signal,
|
|
29
|
-
() => cancelled = true
|
|
30
|
-
);
|
|
31
|
-
const stream = await streamFn(streamFnContext);
|
|
32
|
-
const isReplaceRefetch = isRefetch && refetchMode === "replace";
|
|
33
|
-
for await (const chunk of stream) {
|
|
34
|
-
if (cancelled) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
if (isReplaceRefetch) {
|
|
38
|
-
result = reducer(result, chunk);
|
|
39
|
-
} else {
|
|
40
|
-
context.client.setQueryData(
|
|
41
|
-
context.queryKey,
|
|
42
|
-
(prev) => reducer(prev === void 0 ? initialValue : prev, chunk)
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (isReplaceRefetch && !cancelled) {
|
|
47
|
-
context.client.setQueryData(context.queryKey, result);
|
|
48
|
-
}
|
|
49
|
-
return context.client.getQueryData(context.queryKey) ?? initialValue;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
streamedQuery
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=streamedQuery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defines how re-fetches are handled.\n * Defaults to `'reset'`, erases all data and puts the query back into `pending` state.\n * Set to `'append'` to append new data to the existing data.\n * Set to `'replace'` to write all data to the cache once the stream ends.\n * @param reducer - A function to reduce the streamed chunks into the final data.\n * Defaults to a function that appends chunks to the end of the array.\n * @param initialValue - Initial value to be used while the first chunk is being fetched, and returned if the stream yields no values.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TData = Array<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n>({\n streamFn,\n refetchMode = 'reset',\n reducer = (items, chunk) =>\n addToEnd(items as Array<TQueryFnData>, chunk) as TData,\n initialValue = [] as TData,\n}: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<\n TData,\n TQueryKey\n> {\n return async (context) => {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n const isRefetch = !!query && query.isFetched()\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n ...query.resetState,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n let cancelled: boolean = false as boolean\n const streamFnContext = addConsumeAwareSignal<\n OmitKeyof<typeof context, 'signal'>\n >(\n {\n client: context.client,\n meta: context.meta,\n queryKey: context.queryKey,\n pageParam: context.pageParam,\n direction: context.direction,\n },\n () => context.signal,\n () => (cancelled = true),\n )\n\n const stream = await streamFn(streamFnContext)\n\n const isReplaceRefetch = isRefetch && refetchMode === 'replace'\n\n for await (const chunk of stream) {\n if (cancelled) {\n break\n }\n\n if (isReplaceRefetch) {\n // don't append to the cache directly when replace-refetching\n result = reducer(result, chunk)\n } else {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isReplaceRefetch && !cancelled) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n return context.client.getQueryData(context.queryKey) ?? initialValue\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB,gBAAgB;AAkDzC,SAAS,cAId;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,UAAU,CAAC,OAAO,UAChB,SAAS,OAA8B,KAAK;AAAA,EAC9C,eAAe,CAAC;AAClB,GAGE;AACA,SAAO,OAAO,YAAY;AACxB,UAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAM,YAAY,CAAC,CAAC,SAAS,MAAM,UAAU;AAC7C,QAAI,aAAa,gBAAgB,SAAS;AACxC,YAAM,SAAS;AAAA,QACb,GAAG,MAAM;AAAA,QACT,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAEA,QAAI,SAAS;AAEb,QAAI,YAAqB;AACzB,UAAM,kBAAkB;AAAA,MAGtB;AAAA,QACE,QAAQ,QAAQ;AAAA,QAChB,MAAM,QAAQ;AAAA,QACd,UAAU,QAAQ;AAAA,QAClB,WAAW,QAAQ;AAAA,QACnB,WAAW,QAAQ;AAAA,MACrB;AAAA,MACA,MAAM,QAAQ;AAAA,MACd,MAAO,YAAY;AAAA,IACrB;AAEA,UAAM,SAAS,MAAM,SAAS,eAAe;AAE7C,UAAM,mBAAmB,aAAa,gBAAgB;AAEtD,qBAAiB,SAAS,QAAQ;AAChC,UAAI,WAAW;AACb;AAAA,MACF;AAEA,UAAI,kBAAkB;AAEpB,iBAAS,QAAQ,QAAQ,KAAK;AAAA,MAChC,OAAO;AACL,gBAAQ,OAAO;AAAA,UAAoB,QAAQ;AAAA,UAAU,CAAC,SACpD,QAAQ,SAAS,SAAY,eAAe,MAAM,KAAK;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAGA,QAAI,oBAAoB,CAAC,WAAW;AAClC,cAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;AAAA,IAC7D;AAEA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ,KAAK;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/subscribable.ts
|
|
21
|
-
var subscribable_exports = {};
|
|
22
|
-
__export(subscribable_exports, {
|
|
23
|
-
Subscribable: () => Subscribable
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(subscribable_exports);
|
|
26
|
-
var Subscribable = class {
|
|
27
|
-
constructor() {
|
|
28
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
29
|
-
this.subscribe = this.subscribe.bind(this);
|
|
30
|
-
}
|
|
31
|
-
subscribe(listener) {
|
|
32
|
-
this.listeners.add(listener);
|
|
33
|
-
this.onSubscribe();
|
|
34
|
-
return () => {
|
|
35
|
-
this.listeners.delete(listener);
|
|
36
|
-
this.onUnsubscribe();
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
hasListeners() {
|
|
40
|
-
return this.listeners.size > 0;
|
|
41
|
-
}
|
|
42
|
-
onSubscribe() {
|
|
43
|
-
}
|
|
44
|
-
onUnsubscribe() {
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
-
0 && (module.exports = {
|
|
49
|
-
Subscribable
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=subscribable.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/subscribable.ts"],"sourcesContent":["export class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,eAAN,MAA+C;AAAA,EAGpD,cAAc;AAFd,SAAU,YAAY,oBAAI,IAAe;AAGvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEA,UAAU,UAAiC;AACzC,SAAK,UAAU,IAAI,QAAQ;AAE3B,SAAK,YAAY;AAEjB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO,QAAQ;AAC9B,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,eAAwB;AACtB,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA,EAEU,cAAoB;AAAA,EAE9B;AAAA,EAEU,gBAAsB;AAAA,EAEhC;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Subscribable } from './_tsup-dts-rollup.cjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Subscribable } from './_tsup-dts-rollup.js';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// src/subscribable.ts
|
|
2
|
-
var Subscribable = class {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
5
|
-
this.subscribe = this.subscribe.bind(this);
|
|
6
|
-
}
|
|
7
|
-
subscribe(listener) {
|
|
8
|
-
this.listeners.add(listener);
|
|
9
|
-
this.onSubscribe();
|
|
10
|
-
return () => {
|
|
11
|
-
this.listeners.delete(listener);
|
|
12
|
-
this.onUnsubscribe();
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
hasListeners() {
|
|
16
|
-
return this.listeners.size > 0;
|
|
17
|
-
}
|
|
18
|
-
onSubscribe() {
|
|
19
|
-
}
|
|
20
|
-
onUnsubscribe() {
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
export {
|
|
24
|
-
Subscribable
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=subscribable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/subscribable.ts"],"sourcesContent":["export class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";AAAO,IAAM,eAAN,MAA+C;AAAA,EAGpD,cAAc;AAFd,SAAU,YAAY,oBAAI,IAAe;AAGvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEA,UAAU,UAAiC;AACzC,SAAK,UAAU,IAAI,QAAQ;AAE3B,SAAK,YAAY;AAEjB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO,QAAQ;AAC9B,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,eAAwB;AACtB,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA,EAEU,cAAoB;AAAA,EAE9B;AAAA,EAEU,gBAAsB;AAAA,EAEhC;AACF;","names":[]}
|