@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
|
@@ -1,149 +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/mutationCache.ts
|
|
21
|
-
var mutationCache_exports = {};
|
|
22
|
-
__export(mutationCache_exports, {
|
|
23
|
-
MutationCache: () => MutationCache
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(mutationCache_exports);
|
|
26
|
-
var import_notifyManager = require("./notifyManager.cjs");
|
|
27
|
-
var import_mutation = require("./mutation.cjs");
|
|
28
|
-
var import_utils = require("./utils.cjs");
|
|
29
|
-
var import_subscribable = require("./subscribable.cjs");
|
|
30
|
-
var MutationCache = class extends import_subscribable.Subscribable {
|
|
31
|
-
constructor(config = {}) {
|
|
32
|
-
super();
|
|
33
|
-
this.config = config;
|
|
34
|
-
this.#mutations = /* @__PURE__ */ new Set();
|
|
35
|
-
this.#scopes = /* @__PURE__ */ new Map();
|
|
36
|
-
this.#mutationId = 0;
|
|
37
|
-
}
|
|
38
|
-
#mutations;
|
|
39
|
-
#scopes;
|
|
40
|
-
#mutationId;
|
|
41
|
-
build(client, options, state) {
|
|
42
|
-
const mutation = new import_mutation.Mutation({
|
|
43
|
-
client,
|
|
44
|
-
mutationCache: this,
|
|
45
|
-
mutationId: ++this.#mutationId,
|
|
46
|
-
options: client.defaultMutationOptions(options),
|
|
47
|
-
state
|
|
48
|
-
});
|
|
49
|
-
this.add(mutation);
|
|
50
|
-
return mutation;
|
|
51
|
-
}
|
|
52
|
-
add(mutation) {
|
|
53
|
-
this.#mutations.add(mutation);
|
|
54
|
-
const scope = scopeFor(mutation);
|
|
55
|
-
if (typeof scope === "string") {
|
|
56
|
-
const scopedMutations = this.#scopes.get(scope);
|
|
57
|
-
if (scopedMutations) {
|
|
58
|
-
scopedMutations.push(mutation);
|
|
59
|
-
} else {
|
|
60
|
-
this.#scopes.set(scope, [mutation]);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
this.notify({ type: "added", mutation });
|
|
64
|
-
}
|
|
65
|
-
remove(mutation) {
|
|
66
|
-
if (this.#mutations.delete(mutation)) {
|
|
67
|
-
const scope = scopeFor(mutation);
|
|
68
|
-
if (typeof scope === "string") {
|
|
69
|
-
const scopedMutations = this.#scopes.get(scope);
|
|
70
|
-
if (scopedMutations) {
|
|
71
|
-
if (scopedMutations.length > 1) {
|
|
72
|
-
const index = scopedMutations.indexOf(mutation);
|
|
73
|
-
if (index !== -1) {
|
|
74
|
-
scopedMutations.splice(index, 1);
|
|
75
|
-
}
|
|
76
|
-
} else if (scopedMutations[0] === mutation) {
|
|
77
|
-
this.#scopes.delete(scope);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
this.notify({ type: "removed", mutation });
|
|
83
|
-
}
|
|
84
|
-
canRun(mutation) {
|
|
85
|
-
const scope = scopeFor(mutation);
|
|
86
|
-
if (typeof scope === "string") {
|
|
87
|
-
const mutationsWithSameScope = this.#scopes.get(scope);
|
|
88
|
-
const firstPendingMutation = mutationsWithSameScope?.find(
|
|
89
|
-
(m) => m.state.status === "pending"
|
|
90
|
-
);
|
|
91
|
-
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
92
|
-
} else {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
runNext(mutation) {
|
|
97
|
-
const scope = scopeFor(mutation);
|
|
98
|
-
if (typeof scope === "string") {
|
|
99
|
-
const foundMutation = this.#scopes.get(scope)?.find((m) => m !== mutation && m.state.isPaused);
|
|
100
|
-
return foundMutation?.continue() ?? Promise.resolve();
|
|
101
|
-
} else {
|
|
102
|
-
return Promise.resolve();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
clear() {
|
|
106
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
107
|
-
this.#mutations.forEach((mutation) => {
|
|
108
|
-
this.notify({ type: "removed", mutation });
|
|
109
|
-
});
|
|
110
|
-
this.#mutations.clear();
|
|
111
|
-
this.#scopes.clear();
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
getAll() {
|
|
115
|
-
return Array.from(this.#mutations);
|
|
116
|
-
}
|
|
117
|
-
find(filters) {
|
|
118
|
-
const defaultedFilters = { exact: true, ...filters };
|
|
119
|
-
return this.getAll().find(
|
|
120
|
-
(mutation) => (0, import_utils.matchMutation)(defaultedFilters, mutation)
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
findAll(filters = {}) {
|
|
124
|
-
return this.getAll().filter((mutation) => (0, import_utils.matchMutation)(filters, mutation));
|
|
125
|
-
}
|
|
126
|
-
notify(event) {
|
|
127
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
128
|
-
this.listeners.forEach((listener) => {
|
|
129
|
-
listener(event);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
resumePausedMutations() {
|
|
134
|
-
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
135
|
-
return import_notifyManager.notifyManager.batch(
|
|
136
|
-
() => Promise.all(
|
|
137
|
-
pausedMutations.map((mutation) => mutation.continue().catch(import_utils.noop))
|
|
138
|
-
)
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
function scopeFor(mutation) {
|
|
143
|
-
return mutation.options.scope?.id;
|
|
144
|
-
}
|
|
145
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
-
0 && (module.exports = {
|
|
147
|
-
MutationCache
|
|
148
|
-
});
|
|
149
|
-
//# sourceMappingURL=mutationCache.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,sBAAyB;AACzB,mBAAoC;AACpC,0BAA6B;AAyFtB,IAAM,gBAAN,cAA4B,iCAAoC;AAAA,EAKrE,YAAmB,SAA8B,CAAC,GAAG;AACnD,UAAM;AADW;AAEjB,SAAK,aAAa,oBAAI,IAAI;AAC1B,SAAK,UAAU,oBAAI,IAAI;AACvB,SAAK,cAAc;AAAA,EACrB;AAAA,EATA;AAAA,EACA;AAAA,EACA;AAAA,EASA,MACE,QACA,SACA,OACsD;AACtD,UAAM,WAAW,IAAI,yBAAS;AAAA,MAC5B;AAAA,MACA,eAAe;AAAA,MACf,YAAY,EAAE,KAAK;AAAA,MACnB,SAAS,OAAO,uBAAuB,OAAO;AAAA,MAC9C;AAAA,IACF,CAAC;AAED,SAAK,IAAI,QAAQ;AAEjB,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,UAA8C;AAChD,SAAK,WAAW,IAAI,QAAQ;AAC5B,UAAM,QAAQ,SAAS,QAAQ;AAC/B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,kBAAkB,KAAK,QAAQ,IAAI,KAAK;AAC9C,UAAI,iBAAiB;AACnB,wBAAgB,KAAK,QAAQ;AAAA,MAC/B,OAAO;AACL,aAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;AAAA,MACpC;AAAA,IACF;AACA,SAAK,OAAO,EAAE,MAAM,SAAS,SAAS,CAAC;AAAA,EACzC;AAAA,EAEA,OAAO,UAA8C;AACn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AS,CAAC;AAAA,MAC3C,CAAC;AACD,WAAK,WAAW,MAAM;AACtB,WAAK,QAAQ,MAAM;AAAA,IACrB,CAAC;AAAA,EACH;AAAA,EAEA,SAA0B;AACxB,WAAO,MAAM,KAAK,KAAK,UAAU;AAAA,EACnC;AAAA,EAEA,KAME,SACkE;AAClE,UAAM,mBAAmB,EAAE,OAAO,MAAM,GAAG,QAAQ;AAEnD,WAAO,KAAK,OAAO,EAAE;AAAA,MAAK,CAAC,iBACzB,4BAAc,kBAAkB,QAAQ;AAAA,IAC1C;AAAA,EACF;AAAA,EAEA,QAAQ,UAA2B,CAAC,GAAoB;AACtD,WAAO,KAAK,OAAO,EAAE,OAAO,CAAC,iBAAa,4BAAc,SAAS,QAAQ,CAAC;AAAA,EAC5E;AAAA,EAEA,OAAO,OAAiC;AACtC,uCAAc,MAAM,MAAM;AACxB,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,iBAAS,KAAK;AAAA,MAChB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEA,wBAA0C;AACxC,UAAM,kBAAkB,KAAK,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,QAAQ;AAEpE,WAAO,mCAAc;AAAA,MAAM,MACzB,QAAQ;AAAA,QACN,gBAAgB,IAAI,CAAC,aAAa,SAAS,SAAS,EAAE,MAAM,iBAAI,CAAC;AAAA,MACnE;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,SAAS,UAAwC;AACxD,SAAO,SAAS,QAAQ,OAAO;AACjC;","names":[]}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// src/mutationCache.ts
|
|
2
|
-
import { notifyManager } from "./notifyManager.js";
|
|
3
|
-
import { Mutation } from "./mutation.js";
|
|
4
|
-
import { matchMutation, noop } from "./utils.js";
|
|
5
|
-
import { Subscribable } from "./subscribable.js";
|
|
6
|
-
var MutationCache = class extends Subscribable {
|
|
7
|
-
constructor(config = {}) {
|
|
8
|
-
super();
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.#mutations = /* @__PURE__ */ new Set();
|
|
11
|
-
this.#scopes = /* @__PURE__ */ new Map();
|
|
12
|
-
this.#mutationId = 0;
|
|
13
|
-
}
|
|
14
|
-
#mutations;
|
|
15
|
-
#scopes;
|
|
16
|
-
#mutationId;
|
|
17
|
-
build(client, options, state) {
|
|
18
|
-
const mutation = new Mutation({
|
|
19
|
-
client,
|
|
20
|
-
mutationCache: this,
|
|
21
|
-
mutationId: ++this.#mutationId,
|
|
22
|
-
options: client.defaultMutationOptions(options),
|
|
23
|
-
state
|
|
24
|
-
});
|
|
25
|
-
this.add(mutation);
|
|
26
|
-
return mutation;
|
|
27
|
-
}
|
|
28
|
-
add(mutation) {
|
|
29
|
-
this.#mutations.add(mutation);
|
|
30
|
-
const scope = scopeFor(mutation);
|
|
31
|
-
if (typeof scope === "string") {
|
|
32
|
-
const scopedMutations = this.#scopes.get(scope);
|
|
33
|
-
if (scopedMutations) {
|
|
34
|
-
scopedMutations.push(mutation);
|
|
35
|
-
} else {
|
|
36
|
-
this.#scopes.set(scope, [mutation]);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
this.notify({ type: "added", mutation });
|
|
40
|
-
}
|
|
41
|
-
remove(mutation) {
|
|
42
|
-
if (this.#mutations.delete(mutation)) {
|
|
43
|
-
const scope = scopeFor(mutation);
|
|
44
|
-
if (typeof scope === "string") {
|
|
45
|
-
const scopedMutations = this.#scopes.get(scope);
|
|
46
|
-
if (scopedMutations) {
|
|
47
|
-
if (scopedMutations.length > 1) {
|
|
48
|
-
const index = scopedMutations.indexOf(mutation);
|
|
49
|
-
if (index !== -1) {
|
|
50
|
-
scopedMutations.splice(index, 1);
|
|
51
|
-
}
|
|
52
|
-
} else if (scopedMutations[0] === mutation) {
|
|
53
|
-
this.#scopes.delete(scope);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
this.notify({ type: "removed", mutation });
|
|
59
|
-
}
|
|
60
|
-
canRun(mutation) {
|
|
61
|
-
const scope = scopeFor(mutation);
|
|
62
|
-
if (typeof scope === "string") {
|
|
63
|
-
const mutationsWithSameScope = this.#scopes.get(scope);
|
|
64
|
-
const firstPendingMutation = mutationsWithSameScope?.find(
|
|
65
|
-
(m) => m.state.status === "pending"
|
|
66
|
-
);
|
|
67
|
-
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
68
|
-
} else {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
runNext(mutation) {
|
|
73
|
-
const scope = scopeFor(mutation);
|
|
74
|
-
if (typeof scope === "string") {
|
|
75
|
-
const foundMutation = this.#scopes.get(scope)?.find((m) => m !== mutation && m.state.isPaused);
|
|
76
|
-
return foundMutation?.continue() ?? Promise.resolve();
|
|
77
|
-
} else {
|
|
78
|
-
return Promise.resolve();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
clear() {
|
|
82
|
-
notifyManager.batch(() => {
|
|
83
|
-
this.#mutations.forEach((mutation) => {
|
|
84
|
-
this.notify({ type: "removed", mutation });
|
|
85
|
-
});
|
|
86
|
-
this.#mutations.clear();
|
|
87
|
-
this.#scopes.clear();
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
getAll() {
|
|
91
|
-
return Array.from(this.#mutations);
|
|
92
|
-
}
|
|
93
|
-
find(filters) {
|
|
94
|
-
const defaultedFilters = { exact: true, ...filters };
|
|
95
|
-
return this.getAll().find(
|
|
96
|
-
(mutation) => matchMutation(defaultedFilters, mutation)
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
findAll(filters = {}) {
|
|
100
|
-
return this.getAll().filter((mutation) => matchMutation(filters, mutation));
|
|
101
|
-
}
|
|
102
|
-
notify(event) {
|
|
103
|
-
notifyManager.batch(() => {
|
|
104
|
-
this.listeners.forEach((listener) => {
|
|
105
|
-
listener(event);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
resumePausedMutations() {
|
|
110
|
-
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
111
|
-
return notifyManager.batch(
|
|
112
|
-
() => Promise.all(
|
|
113
|
-
pausedMutations.map((mutation) => mutation.continue().catch(noop))
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
function scopeFor(mutation) {
|
|
119
|
-
return mutation.options.scope?.id;
|
|
120
|
-
}
|
|
121
|
-
export {
|
|
122
|
-
MutationCache
|
|
123
|
-
};
|
|
124
|
-
//# sourceMappingURL=mutationCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,eAAe,YAAY;AACpC,SAAS,oBAAoB;AAyFtB,IAAM,gBAAN,cAA4B,aAAoC;AAAA,EAKrE,YAAmB,SAA8B,CAAC,GAAG;AACnD,UAAM;AADW;AAEjB,SAAK,aAAa,oBAAI,IAAI;AAC1B,SAAK,UAAU,oBAAI,IAAI;AACvB,SAAK,cAAc;AAAA,EACrB;AAAA,EATA;AAAA,EACA;AAAA,EACA;AAAA,EASA,MACE,QACA,SACA,OACsD;AACtD,UAAM,WAAW,IAAI,SAAS;AAAA,MAC5B;AAAA,MACA,eAAe;AAAA,MACf,YAAY,EAAE,KAAK;AAAA,MACnB,SAAS,OAAO,uBAAuB,OAAO;AAAA,MAC9C;AAAA,IACF,CAAC;AAED,SAAK,IAAI,QAAQ;AAEjB,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,UAA8C;AAChD,SAAK,WAAW,IAAI,QAAQ;AAC5B,UAAM,QAAQ,SAAS,QAAQ;AAC/B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,k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 @@
|
|
|
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/mutationObserver.ts
|
|
21
|
-
var mutationObserver_exports = {};
|
|
22
|
-
__export(mutationObserver_exports, {
|
|
23
|
-
MutationObserver: () => MutationObserver
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(mutationObserver_exports);
|
|
26
|
-
var import_mutation = require("./mutation.cjs");
|
|
27
|
-
var import_notifyManager = require("./notifyManager.cjs");
|
|
28
|
-
var import_subscribable = require("./subscribable.cjs");
|
|
29
|
-
var import_utils = require("./utils.cjs");
|
|
30
|
-
var MutationObserver = class extends import_subscribable.Subscribable {
|
|
31
|
-
#client;
|
|
32
|
-
#currentResult = void 0;
|
|
33
|
-
#currentMutation;
|
|
34
|
-
#mutateOptions;
|
|
35
|
-
constructor(client, options) {
|
|
36
|
-
super();
|
|
37
|
-
this.#client = client;
|
|
38
|
-
this.setOptions(options);
|
|
39
|
-
this.bindMethods();
|
|
40
|
-
this.#updateResult();
|
|
41
|
-
}
|
|
42
|
-
bindMethods() {
|
|
43
|
-
this.mutate = this.mutate.bind(this);
|
|
44
|
-
this.reset = this.reset.bind(this);
|
|
45
|
-
}
|
|
46
|
-
setOptions(options) {
|
|
47
|
-
const prevOptions = this.options;
|
|
48
|
-
this.options = this.#client.defaultMutationOptions(options);
|
|
49
|
-
if (!(0, import_utils.shallowEqualObjects)(this.options, prevOptions)) {
|
|
50
|
-
this.#client.getMutationCache().notify({
|
|
51
|
-
type: "observerOptionsUpdated",
|
|
52
|
-
mutation: this.#currentMutation,
|
|
53
|
-
observer: this
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (prevOptions?.mutationKey && this.options.mutationKey && (0, import_utils.hashKey)(prevOptions.mutationKey) !== (0, import_utils.hashKey)(this.options.mutationKey)) {
|
|
57
|
-
this.reset();
|
|
58
|
-
} else if (this.#currentMutation?.state.status === "pending") {
|
|
59
|
-
this.#currentMutation.setOptions(this.options);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
onUnsubscribe() {
|
|
63
|
-
if (!this.hasListeners()) {
|
|
64
|
-
this.#currentMutation?.removeObserver(this);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
onMutationUpdate(action) {
|
|
68
|
-
this.#updateResult();
|
|
69
|
-
this.#notify(action);
|
|
70
|
-
}
|
|
71
|
-
getCurrentResult() {
|
|
72
|
-
return this.#currentResult;
|
|
73
|
-
}
|
|
74
|
-
reset() {
|
|
75
|
-
this.#currentMutation?.removeObserver(this);
|
|
76
|
-
this.#currentMutation = void 0;
|
|
77
|
-
this.#updateResult();
|
|
78
|
-
this.#notify();
|
|
79
|
-
}
|
|
80
|
-
mutate(variables, options) {
|
|
81
|
-
this.#mutateOptions = options;
|
|
82
|
-
this.#currentMutation?.removeObserver(this);
|
|
83
|
-
this.#currentMutation = this.#client.getMutationCache().build(this.#client, this.options);
|
|
84
|
-
this.#currentMutation.addObserver(this);
|
|
85
|
-
return this.#currentMutation.execute(variables);
|
|
86
|
-
}
|
|
87
|
-
#updateResult() {
|
|
88
|
-
const state = this.#currentMutation?.state ?? (0, import_mutation.getDefaultState)();
|
|
89
|
-
this.#currentResult = {
|
|
90
|
-
...state,
|
|
91
|
-
isPending: state.status === "pending",
|
|
92
|
-
isSuccess: state.status === "success",
|
|
93
|
-
isError: state.status === "error",
|
|
94
|
-
isIdle: state.status === "idle",
|
|
95
|
-
mutate: this.mutate,
|
|
96
|
-
reset: this.reset
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
#notify(action) {
|
|
100
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
101
|
-
if (this.#mutateOptions && this.hasListeners()) {
|
|
102
|
-
const variables = this.#currentResult.variables;
|
|
103
|
-
const onMutateResult = this.#currentResult.context;
|
|
104
|
-
const context = {
|
|
105
|
-
client: this.#client,
|
|
106
|
-
meta: this.options.meta,
|
|
107
|
-
mutationKey: this.options.mutationKey
|
|
108
|
-
};
|
|
109
|
-
if (action?.type === "success") {
|
|
110
|
-
try {
|
|
111
|
-
this.#mutateOptions.onSuccess?.(
|
|
112
|
-
action.data,
|
|
113
|
-
variables,
|
|
114
|
-
onMutateResult,
|
|
115
|
-
context
|
|
116
|
-
);
|
|
117
|
-
} catch (e) {
|
|
118
|
-
void Promise.reject(e);
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
this.#mutateOptions.onSettled?.(
|
|
122
|
-
action.data,
|
|
123
|
-
null,
|
|
124
|
-
variables,
|
|
125
|
-
onMutateResult,
|
|
126
|
-
context
|
|
127
|
-
);
|
|
128
|
-
} catch (e) {
|
|
129
|
-
void Promise.reject(e);
|
|
130
|
-
}
|
|
131
|
-
} else if (action?.type === "error") {
|
|
132
|
-
try {
|
|
133
|
-
this.#mutateOptions.onError?.(
|
|
134
|
-
action.error,
|
|
135
|
-
variables,
|
|
136
|
-
onMutateResult,
|
|
137
|
-
context
|
|
138
|
-
);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
void Promise.reject(e);
|
|
141
|
-
}
|
|
142
|
-
try {
|
|
143
|
-
this.#mutateOptions.onSettled?.(
|
|
144
|
-
void 0,
|
|
145
|
-
action.error,
|
|
146
|
-
variables,
|
|
147
|
-
onMutateResult,
|
|
148
|
-
context
|
|
149
|
-
);
|
|
150
|
-
} catch (e) {
|
|
151
|
-
void Promise.reject(e);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
this.listeners.forEach((listener) => {
|
|
156
|
-
listener(this.#currentResult);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
162
|
-
0 && (module.exports = {
|
|
163
|
-
MutationObserver
|
|
164
|
-
});
|
|
165
|
-
//# sourceMappingURL=mutationObserver.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mutationObserver.ts"],"sourcesContent":["import { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport { hashKey, shallowEqualObjects } from './utils'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n MutateOptions,\n MutationFunctionContext,\n MutationObserverOptions,\n MutationObserverResult,\n} from './types'\nimport type { Action, Mutation } from './mutation'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (\n result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n) => void\n\n// CLASS\n\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TOnMutateResult>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TOnMutateResult>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TOnMutateResult>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n super()\n\n this.#client = client\n this.setOptions(options)\n this.bindMethods()\n this.#updateResult()\n }\n\n protected bindMethods(): void {\n this.mutate = this.mutate.bind(this)\n this.reset = this.reset.bind(this)\n }\n\n setOptions(\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n const prevOptions = this.options as\n | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n | undefined\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(this.options, prevOptions)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n\n if (\n prevOptions?.mutationKey &&\n this.options.mutationKey &&\n hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)\n ) {\n this.reset()\n } else if (this.#currentMutation?.state.status === 'pending') {\n this.#currentMutation.setOptions(this.options)\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n onMutationUpdate(\n action: Action<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > {\n return this.#currentResult\n }\n\n reset(): void {\n // reset needs to remove the observer from the mutation because there is no way to \"get it back\"\n // another mutate call will yield a new mutation!\n this.#currentMutation?.removeObserver(this)\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,\n ): Promise<TData> {\n this.#mutateOptions = options\n\n this.#currentMutation?.removeObserver(this)\n\n this.#currentMutation = this.#client\n .getMutationCache()\n .build(this.#client, this.options)\n\n this.#currentMutation.addObserver(this)\n\n return this.#currentMutation.execute(variables)\n }\n\n #updateResult(): void {\n const state =\n this.#currentMutation?.state ??\n getDefaultState<TData, TError, TVariables, TOnMutateResult>()\n\n this.#currentResult = {\n ...state,\n isPending: state.status === 'pending',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n isIdle: state.status === 'idle',\n mutate: this.mutate,\n reset: this.reset,\n } as MutationObserverResult<TData, TError, TVariables, TOnMutateResult>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n if (this.#mutateOptions && this.hasListeners()) {\n const variables = this.#currentResult.variables!\n const onMutateResult = this.#currentResult.context\n\n const context = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n if (action?.type === 'success') {\n try {\n this.#mutateOptions.onSuccess?.(\n action.data,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n action.data,\n null,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n } else if (action?.type === 'error') {\n try {\n this.#mutateOptions.onError?.(\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n undefined,\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAgC;AAChC,2BAA8B;AAC9B,0BAA6B;AAC7B,mBAA6C;AAmBtC,IAAM,mBAAN,cAKG,iCAER;AAAA,EAGA;AAAA,EACA,iBAKI;AAAA,EACJ;AAAA,EACA;AAAA,EAEA,YACE,QACA,SAMA;AACA,UAAM;AAEN,SAAK,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AAAA,cAClB;AAAA,cACA,OAAO;AAAA,cACP;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF,SAAS,GAAG;AACV,iBAAK,QAAQ,OAAO,CAAC;AAAA,UACvB;AAAA,QACF;AAAA,MACF;AAGA,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,iBAAS,KAAK,cAAc;AAAA,MAC9B,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MutationObserver_alias_1 as MutationObserver } from './_tsup-dts-rollup.cjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MutationObserver_alias_1 as MutationObserver } from './_tsup-dts-rollup.js';
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// src/mutationObserver.ts
|
|
2
|
-
import { getDefaultState } from "./mutation.js";
|
|
3
|
-
import { notifyManager } from "./notifyManager.js";
|
|
4
|
-
import { Subscribable } from "./subscribable.js";
|
|
5
|
-
import { hashKey, shallowEqualObjects } from "./utils.js";
|
|
6
|
-
var MutationObserver = class extends Subscribable {
|
|
7
|
-
#client;
|
|
8
|
-
#currentResult = void 0;
|
|
9
|
-
#currentMutation;
|
|
10
|
-
#mutateOptions;
|
|
11
|
-
constructor(client, options) {
|
|
12
|
-
super();
|
|
13
|
-
this.#client = client;
|
|
14
|
-
this.setOptions(options);
|
|
15
|
-
this.bindMethods();
|
|
16
|
-
this.#updateResult();
|
|
17
|
-
}
|
|
18
|
-
bindMethods() {
|
|
19
|
-
this.mutate = this.mutate.bind(this);
|
|
20
|
-
this.reset = this.reset.bind(this);
|
|
21
|
-
}
|
|
22
|
-
setOptions(options) {
|
|
23
|
-
const prevOptions = this.options;
|
|
24
|
-
this.options = this.#client.defaultMutationOptions(options);
|
|
25
|
-
if (!shallowEqualObjects(this.options, prevOptions)) {
|
|
26
|
-
this.#client.getMutationCache().notify({
|
|
27
|
-
type: "observerOptionsUpdated",
|
|
28
|
-
mutation: this.#currentMutation,
|
|
29
|
-
observer: this
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
if (prevOptions?.mutationKey && this.options.mutationKey && hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)) {
|
|
33
|
-
this.reset();
|
|
34
|
-
} else if (this.#currentMutation?.state.status === "pending") {
|
|
35
|
-
this.#currentMutation.setOptions(this.options);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
onUnsubscribe() {
|
|
39
|
-
if (!this.hasListeners()) {
|
|
40
|
-
this.#currentMutation?.removeObserver(this);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
onMutationUpdate(action) {
|
|
44
|
-
this.#updateResult();
|
|
45
|
-
this.#notify(action);
|
|
46
|
-
}
|
|
47
|
-
getCurrentResult() {
|
|
48
|
-
return this.#currentResult;
|
|
49
|
-
}
|
|
50
|
-
reset() {
|
|
51
|
-
this.#currentMutation?.removeObserver(this);
|
|
52
|
-
this.#currentMutation = void 0;
|
|
53
|
-
this.#updateResult();
|
|
54
|
-
this.#notify();
|
|
55
|
-
}
|
|
56
|
-
mutate(variables, options) {
|
|
57
|
-
this.#mutateOptions = options;
|
|
58
|
-
this.#currentMutation?.removeObserver(this);
|
|
59
|
-
this.#currentMutation = this.#client.getMutationCache().build(this.#client, this.options);
|
|
60
|
-
this.#currentMutation.addObserver(this);
|
|
61
|
-
return this.#currentMutation.execute(variables);
|
|
62
|
-
}
|
|
63
|
-
#updateResult() {
|
|
64
|
-
const state = this.#currentMutation?.state ?? getDefaultState();
|
|
65
|
-
this.#currentResult = {
|
|
66
|
-
...state,
|
|
67
|
-
isPending: state.status === "pending",
|
|
68
|
-
isSuccess: state.status === "success",
|
|
69
|
-
isError: state.status === "error",
|
|
70
|
-
isIdle: state.status === "idle",
|
|
71
|
-
mutate: this.mutate,
|
|
72
|
-
reset: this.reset
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
#notify(action) {
|
|
76
|
-
notifyManager.batch(() => {
|
|
77
|
-
if (this.#mutateOptions && this.hasListeners()) {
|
|
78
|
-
const variables = this.#currentResult.variables;
|
|
79
|
-
const onMutateResult = this.#currentResult.context;
|
|
80
|
-
const context = {
|
|
81
|
-
client: this.#client,
|
|
82
|
-
meta: this.options.meta,
|
|
83
|
-
mutationKey: this.options.mutationKey
|
|
84
|
-
};
|
|
85
|
-
if (action?.type === "success") {
|
|
86
|
-
try {
|
|
87
|
-
this.#mutateOptions.onSuccess?.(
|
|
88
|
-
action.data,
|
|
89
|
-
variables,
|
|
90
|
-
onMutateResult,
|
|
91
|
-
context
|
|
92
|
-
);
|
|
93
|
-
} catch (e) {
|
|
94
|
-
void Promise.reject(e);
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
this.#mutateOptions.onSettled?.(
|
|
98
|
-
action.data,
|
|
99
|
-
null,
|
|
100
|
-
variables,
|
|
101
|
-
onMutateResult,
|
|
102
|
-
context
|
|
103
|
-
);
|
|
104
|
-
} catch (e) {
|
|
105
|
-
void Promise.reject(e);
|
|
106
|
-
}
|
|
107
|
-
} else if (action?.type === "error") {
|
|
108
|
-
try {
|
|
109
|
-
this.#mutateOptions.onError?.(
|
|
110
|
-
action.error,
|
|
111
|
-
variables,
|
|
112
|
-
onMutateResult,
|
|
113
|
-
context
|
|
114
|
-
);
|
|
115
|
-
} catch (e) {
|
|
116
|
-
void Promise.reject(e);
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
this.#mutateOptions.onSettled?.(
|
|
120
|
-
void 0,
|
|
121
|
-
action.error,
|
|
122
|
-
variables,
|
|
123
|
-
onMutateResult,
|
|
124
|
-
context
|
|
125
|
-
);
|
|
126
|
-
} catch (e) {
|
|
127
|
-
void Promise.reject(e);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
this.listeners.forEach((listener) => {
|
|
132
|
-
listener(this.#currentResult);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
export {
|
|
138
|
-
MutationObserver
|
|
139
|
-
};
|
|
140
|
-
//# sourceMappingURL=mutationObserver.js.map
|