react-redux-cache 0.22.1 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/createActions.js +63 -63
- package/dist/cjs/createCache.js +216 -131
- package/dist/cjs/createReducer.js +355 -290
- package/dist/cjs/createSelectors.js +66 -58
- package/dist/cjs/index.js +87 -26
- package/dist/cjs/mutate.js +153 -70
- package/dist/cjs/query.js +161 -70
- package/dist/cjs/types.js +2 -2
- package/dist/cjs/useMutation.js +81 -42
- package/dist/cjs/useQuery.js +127 -56
- package/dist/cjs/utilsAndConstants.js +204 -151
- package/dist/esm/createActions.js +60 -59
- package/dist/esm/createCache.js +218 -127
- package/dist/esm/createReducer.js +349 -286
- package/dist/esm/createSelectors.js +63 -54
- package/dist/esm/index.js +3 -3
- package/dist/esm/mutate.js +143 -66
- package/dist/esm/query.js +149 -66
- package/dist/esm/types.js +1 -1
- package/dist/esm/useMutation.js +77 -38
- package/dist/esm/useQuery.js +119 -52
- package/dist/esm/utilsAndConstants.js +190 -140
- package/dist/types/createActions.d.ts +109 -83
- package/dist/types/createCache.d.ts +734 -409
- package/dist/types/createReducer.d.ts +11 -3
- package/dist/types/createSelectors.d.ts +80 -18
- package/dist/types/index.d.ts +3 -3
- package/dist/types/mutate.d.ts +94 -4
- package/dist/types/query.d.ts +123 -4
- package/dist/types/types.d.ts +360 -184
- package/dist/types/useMutation.d.ts +39 -4
- package/dist/types/useQuery.d.ts +40 -4
- package/dist/types/utilsAndConstants.d.ts +56 -23
- package/package.json +4 -5
|
@@ -1,297 +1,360 @@
|
|
|
1
|
-
var __rest =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var __rest =
|
|
2
|
+
(this && this.__rest) ||
|
|
3
|
+
function (s, e) {
|
|
4
|
+
var t = {}
|
|
5
|
+
for (var p in s) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) {
|
|
7
|
+
t[p] = s[p]
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
if (s != null && typeof Object.getOwnPropertySymbols === 'function') {
|
|
11
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
12
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) {
|
|
13
|
+
t[p[i]] = s[p[i]]
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return t
|
|
18
|
+
}
|
|
19
|
+
import {
|
|
20
|
+
applyEntityChanges,
|
|
21
|
+
EMPTY_OBJECT,
|
|
22
|
+
incrementChangeKey,
|
|
23
|
+
isEmptyObject,
|
|
24
|
+
logDebug,
|
|
25
|
+
optionalUtils,
|
|
26
|
+
} from './utilsAndConstants'
|
|
27
|
+
const optionalQueryKeys = ['error', 'expiresAt', 'result', 'params', 'loading']
|
|
28
|
+
const optionalMutationKeys = ['error', 'result', 'params', 'loading']
|
|
29
|
+
|
|
26
30
|
export const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
31
|
+
const mutable = cacheOptions.mutableCollections
|
|
32
|
+
cacheOptions.logsEnabled &&
|
|
33
|
+
logDebug('createReducer', {
|
|
34
|
+
queryKeys,
|
|
35
|
+
mutable,
|
|
36
|
+
})
|
|
37
|
+
const getMutableInitialState = mutable
|
|
38
|
+
? () => {
|
|
39
|
+
return {
|
|
40
|
+
entities: {},
|
|
41
|
+
queries: queryKeys.reduce((result, x) => {
|
|
42
|
+
result[x] = {}
|
|
43
|
+
return result
|
|
44
|
+
}, {}),
|
|
45
|
+
mutations: {},
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const newEntities = entityChanges && applyEntityChanges(state.entities, entityChanges, cacheOptions);
|
|
84
|
-
let newState;
|
|
85
|
-
if (newEntities) {
|
|
86
|
-
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
87
|
-
newState.entities = newEntities;
|
|
88
|
-
}
|
|
89
|
-
if (newQueryState) {
|
|
90
|
-
if (!isEmptyObject(newQueryState)) {
|
|
91
|
-
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
92
|
-
if (mutable) {
|
|
93
|
-
newState.queries[queryKey][queryCacheKey] = newQueryState;
|
|
94
|
-
incrementChangeKey(newState.queries);
|
|
95
|
-
incrementChangeKey(newState.queries[queryKey]);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
newState.queries = Object.assign(Object.assign({}, state.queries), { [queryKey]: Object.assign(Object.assign({}, state.queries[queryKey]), { [queryCacheKey]: newQueryState }) });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else if (oldQueryState !== undefined) {
|
|
102
|
-
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
103
|
-
if (mutable) {
|
|
104
|
-
delete newState.queries[queryKey][queryCacheKey];
|
|
105
|
-
incrementChangeKey(newState.queries);
|
|
106
|
-
incrementChangeKey(newState.queries[queryKey]);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const _a = state.queries[queryKey], _b = queryCacheKey, _ = _a[_b], withoutCacheKey = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
110
|
-
newState.queries = Object.assign(Object.assign({}, state.queries), { [queryKey]: withoutCacheKey });
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return newState !== null && newState !== void 0 ? newState : state;
|
|
47
|
+
}
|
|
48
|
+
: undefined
|
|
49
|
+
const immutableInitialState = mutable
|
|
50
|
+
? undefined
|
|
51
|
+
: Object.freeze({
|
|
52
|
+
entities: Object.freeze({}),
|
|
53
|
+
queries: Object.freeze(
|
|
54
|
+
queryKeys.reduce((result, x) => {
|
|
55
|
+
result[x] = Object.freeze({})
|
|
56
|
+
return result
|
|
57
|
+
}, {}),
|
|
58
|
+
),
|
|
59
|
+
mutations: Object.freeze({}),
|
|
60
|
+
})
|
|
61
|
+
const {
|
|
62
|
+
clearCache,
|
|
63
|
+
clearMutationState,
|
|
64
|
+
clearQueryState,
|
|
65
|
+
invalidateQuery,
|
|
66
|
+
mergeEntityChanges,
|
|
67
|
+
updateMutationStateAndEntities,
|
|
68
|
+
updateQueryStateAndEntities,
|
|
69
|
+
} = actions
|
|
70
|
+
const deepEqual = cacheOptions.deepComparisonEnabled ? optionalUtils.deepEqual : undefined
|
|
71
|
+
return (state = mutable ? getMutableInitialState() : immutableInitialState, action) => {
|
|
72
|
+
switch (action.type) {
|
|
73
|
+
case updateQueryStateAndEntities.type: {
|
|
74
|
+
const {queryKey, queryCacheKey, state: queryState, entityChanges} = action
|
|
75
|
+
const oldQueryState = state.queries[queryKey][queryCacheKey]
|
|
76
|
+
let newQueryState = queryState && Object.assign(Object.assign({}, oldQueryState), queryState)
|
|
77
|
+
if (newQueryState) {
|
|
78
|
+
if (oldQueryState && deepEqual) {
|
|
79
|
+
if (
|
|
80
|
+
newQueryState.params !== oldQueryState.params &&
|
|
81
|
+
deepEqual(newQueryState.params, oldQueryState.params)
|
|
82
|
+
) {
|
|
83
|
+
newQueryState.params = oldQueryState.params
|
|
115
84
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (oldMutationState && deepEqual) {
|
|
122
|
-
if (newMutationState.params !== oldMutationState.params &&
|
|
123
|
-
deepEqual(newMutationState.params, oldMutationState.params)) {
|
|
124
|
-
newMutationState.params = oldMutationState.params;
|
|
125
|
-
}
|
|
126
|
-
if (newMutationState.result !== oldMutationState.result &&
|
|
127
|
-
deepEqual(newMutationState.result, oldMutationState.result)) {
|
|
128
|
-
newMutationState.result = oldMutationState.result;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
for (const key of optionalMutationKeys) {
|
|
132
|
-
if (key in newMutationState && newMutationState[key] === undefined) {
|
|
133
|
-
delete newMutationState[key];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldMutationState !== null && oldMutationState !== void 0 ? oldMutationState : EMPTY_OBJECT, newMutationState)) {
|
|
137
|
-
newMutationState = undefined;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const newEntities = entityChanges && applyEntityChanges(state.entities, entityChanges, cacheOptions);
|
|
141
|
-
let newState;
|
|
142
|
-
if (newEntities) {
|
|
143
|
-
newState = Object.assign(Object.assign({}, state), { entities: newEntities });
|
|
144
|
-
}
|
|
145
|
-
if (newMutationState) {
|
|
146
|
-
if (!isEmptyObject(newMutationState)) {
|
|
147
|
-
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
148
|
-
if (mutable) {
|
|
149
|
-
state.mutations[mutationKey] = newMutationState;
|
|
150
|
-
incrementChangeKey(state.mutations);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
newState.mutations = Object.assign(Object.assign({}, state.mutations), { [mutationKey]: newMutationState });
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else if (oldMutationState !== undefined) {
|
|
157
|
-
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
158
|
-
if (mutable) {
|
|
159
|
-
delete state.mutations[mutationKey];
|
|
160
|
-
incrementChangeKey(state.mutations);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
const _c = state.mutations, _d = mutationKey, _ = _c[_d], withoutMutationKey = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
|
|
164
|
-
newState.mutations = withoutMutationKey;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return newState !== null && newState !== void 0 ? newState : state;
|
|
85
|
+
if (
|
|
86
|
+
newQueryState.result !== oldQueryState.result &&
|
|
87
|
+
deepEqual(newQueryState.result, oldQueryState.result)
|
|
88
|
+
) {
|
|
89
|
+
newQueryState.result = oldQueryState.result
|
|
169
90
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
91
|
+
}
|
|
92
|
+
for (const key of optionalQueryKeys) {
|
|
93
|
+
if (key in newQueryState && newQueryState[key] === undefined) {
|
|
94
|
+
delete newQueryState[key]
|
|
174
95
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
96
|
+
}
|
|
97
|
+
if (
|
|
98
|
+
deepEqual === null || deepEqual === void 0
|
|
99
|
+
? void 0
|
|
100
|
+
: deepEqual(
|
|
101
|
+
oldQueryState !== null && oldQueryState !== void 0 ? oldQueryState : EMPTY_OBJECT,
|
|
102
|
+
newQueryState,
|
|
103
|
+
)
|
|
104
|
+
) {
|
|
105
|
+
newQueryState = undefined
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const newEntities = entityChanges && applyEntityChanges(state.entities, entityChanges, cacheOptions)
|
|
109
|
+
let newState
|
|
110
|
+
if (newEntities) {
|
|
111
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
112
|
+
newState.entities = newEntities
|
|
113
|
+
}
|
|
114
|
+
if (newQueryState) {
|
|
115
|
+
if (!isEmptyObject(newQueryState)) {
|
|
116
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
117
|
+
if (mutable) {
|
|
118
|
+
newState.queries[queryKey][queryCacheKey] = newQueryState
|
|
119
|
+
incrementChangeKey(newState.queries)
|
|
120
|
+
incrementChangeKey(newState.queries[queryKey])
|
|
121
|
+
} else {
|
|
122
|
+
newState.queries = Object.assign(Object.assign({}, state.queries), {
|
|
123
|
+
[queryKey]: Object.assign(Object.assign({}, state.queries[queryKey]), {
|
|
124
|
+
[queryCacheKey]: newQueryState,
|
|
125
|
+
}),
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
} else if (oldQueryState !== undefined) {
|
|
129
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
130
|
+
if (mutable) {
|
|
131
|
+
delete newState.queries[queryKey][queryCacheKey]
|
|
132
|
+
incrementChangeKey(newState.queries)
|
|
133
|
+
incrementChangeKey(newState.queries[queryKey])
|
|
134
|
+
} else {
|
|
135
|
+
const _a = state.queries[queryKey],
|
|
136
|
+
_b = queryCacheKey,
|
|
137
|
+
_ = _a[_b],
|
|
138
|
+
withoutCacheKey = __rest(_a, [typeof _b === 'symbol' ? _b : _b + ''])
|
|
139
|
+
newState.queries = Object.assign(Object.assign({}, state.queries), {
|
|
140
|
+
[queryKey]: withoutCacheKey,
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return newState !== null && newState !== void 0 ? newState : state
|
|
146
|
+
}
|
|
147
|
+
case updateMutationStateAndEntities.type: {
|
|
148
|
+
const {mutationKey, state: mutationState, entityChanges} = action
|
|
149
|
+
const oldMutationState = state.mutations[mutationKey]
|
|
150
|
+
let newMutationState =
|
|
151
|
+
mutationState && Object.assign(Object.assign({}, oldMutationState), mutationState)
|
|
152
|
+
if (newMutationState) {
|
|
153
|
+
if (oldMutationState && deepEqual) {
|
|
154
|
+
if (
|
|
155
|
+
newMutationState.params !== oldMutationState.params &&
|
|
156
|
+
deepEqual(newMutationState.params, oldMutationState.params)
|
|
157
|
+
) {
|
|
158
|
+
newMutationState.params = oldMutationState.params
|
|
159
|
+
}
|
|
160
|
+
if (
|
|
161
|
+
newMutationState.result !== oldMutationState.result &&
|
|
162
|
+
deepEqual(newMutationState.result, oldMutationState.result)
|
|
163
|
+
) {
|
|
164
|
+
newMutationState.result = oldMutationState.result
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const key of optionalMutationKeys) {
|
|
168
|
+
if (key in newMutationState && newMutationState[key] === undefined) {
|
|
169
|
+
delete newMutationState[key]
|
|
223
170
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
171
|
+
}
|
|
172
|
+
if (
|
|
173
|
+
deepEqual === null || deepEqual === void 0
|
|
174
|
+
? void 0
|
|
175
|
+
: deepEqual(
|
|
176
|
+
oldMutationState !== null && oldMutationState !== void 0 ? oldMutationState : EMPTY_OBJECT,
|
|
177
|
+
newMutationState,
|
|
178
|
+
)
|
|
179
|
+
) {
|
|
180
|
+
newMutationState = undefined
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const newEntities = entityChanges && applyEntityChanges(state.entities, entityChanges, cacheOptions)
|
|
184
|
+
let newState
|
|
185
|
+
if (newEntities) {
|
|
186
|
+
newState = Object.assign(Object.assign({}, state), {entities: newEntities})
|
|
187
|
+
}
|
|
188
|
+
if (newMutationState) {
|
|
189
|
+
if (!isEmptyObject(newMutationState)) {
|
|
190
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
191
|
+
if (mutable) {
|
|
192
|
+
state.mutations[mutationKey] = newMutationState
|
|
193
|
+
incrementChangeKey(state.mutations)
|
|
194
|
+
} else {
|
|
195
|
+
newState.mutations = Object.assign(Object.assign({}, state.mutations), {
|
|
196
|
+
[mutationKey]: newMutationState,
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
} else if (oldMutationState !== undefined) {
|
|
200
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
201
|
+
if (mutable) {
|
|
202
|
+
delete state.mutations[mutationKey]
|
|
203
|
+
incrementChangeKey(state.mutations)
|
|
204
|
+
} else {
|
|
205
|
+
const _c = state.mutations,
|
|
206
|
+
_d = mutationKey,
|
|
207
|
+
_ = _c[_d],
|
|
208
|
+
withoutMutationKey = __rest(_c, [typeof _d === 'symbol' ? _d : _d + ''])
|
|
209
|
+
newState.mutations = withoutMutationKey
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return newState !== null && newState !== void 0 ? newState : state
|
|
214
|
+
}
|
|
215
|
+
case mergeEntityChanges.type: {
|
|
216
|
+
const {changes} = action
|
|
217
|
+
const newEntities = applyEntityChanges(state.entities, changes, cacheOptions)
|
|
218
|
+
return newEntities ? Object.assign(Object.assign({}, state), {entities: newEntities}) : state
|
|
219
|
+
}
|
|
220
|
+
case invalidateQuery.type: {
|
|
221
|
+
const {queries: queriesToInvalidate} = action
|
|
222
|
+
if (queriesToInvalidate.length === 0) {
|
|
223
|
+
return state
|
|
224
|
+
}
|
|
225
|
+
const now = Date.now()
|
|
226
|
+
let newStatesByQueryKey
|
|
227
|
+
const copiedQueryKeys = mutable ? undefined : new Set()
|
|
228
|
+
for (const {query: queryKey, cacheKey, expiresAt = now} of queriesToInvalidate) {
|
|
229
|
+
const statesByCacheKey = (
|
|
230
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
231
|
+
? newStatesByQueryKey
|
|
232
|
+
: state.queries
|
|
233
|
+
)[queryKey]
|
|
234
|
+
const cacheKeysToInvalidate = cacheKey != null ? [cacheKey] : Object.keys(statesByCacheKey)
|
|
235
|
+
for (const cacheKey of cacheKeysToInvalidate) {
|
|
236
|
+
const queryState = statesByCacheKey[cacheKey]
|
|
237
|
+
if (!queryState || queryState.expiresAt === expiresAt) {
|
|
238
|
+
continue
|
|
267
239
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return state;
|
|
282
|
-
}
|
|
283
|
-
if (mutable) {
|
|
284
|
-
incrementChangeKey(newMutations);
|
|
285
|
-
}
|
|
286
|
-
return Object.assign(Object.assign({}, state), { mutations: newMutations });
|
|
240
|
+
if (mutable) {
|
|
241
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
242
|
+
? newStatesByQueryKey
|
|
243
|
+
: (newStatesByQueryKey = state.queries)
|
|
244
|
+
incrementChangeKey(newStatesByQueryKey[queryKey])
|
|
245
|
+
} else {
|
|
246
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
247
|
+
? newStatesByQueryKey
|
|
248
|
+
: (newStatesByQueryKey = Object.assign({}, state.queries))
|
|
249
|
+
if (!copiedQueryKeys.has(queryKey)) {
|
|
250
|
+
newStatesByQueryKey[queryKey] = Object.assign({}, newStatesByQueryKey[queryKey])
|
|
251
|
+
copiedQueryKeys.add(queryKey)
|
|
252
|
+
}
|
|
287
253
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
254
|
+
if (expiresAt !== undefined) {
|
|
255
|
+
newStatesByQueryKey[queryKey][cacheKey] = Object.assign(Object.assign({}, queryState), {
|
|
256
|
+
expiresAt,
|
|
257
|
+
})
|
|
258
|
+
} else {
|
|
259
|
+
const {expiresAt: _} = queryState,
|
|
260
|
+
newQueryState = __rest(queryState, ['expiresAt'])
|
|
261
|
+
if (isEmptyObject(newQueryState)) {
|
|
262
|
+
delete newStatesByQueryKey[queryKey][cacheKey]
|
|
263
|
+
} else {
|
|
264
|
+
newStatesByQueryKey[queryKey][cacheKey] = newQueryState
|
|
265
|
+
}
|
|
293
266
|
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (!newStatesByQueryKey) {
|
|
270
|
+
return state
|
|
271
|
+
}
|
|
272
|
+
if (mutable) {
|
|
273
|
+
incrementChangeKey(newStatesByQueryKey)
|
|
274
|
+
}
|
|
275
|
+
return Object.assign(Object.assign({}, state), {queries: newStatesByQueryKey})
|
|
276
|
+
}
|
|
277
|
+
case clearQueryState.type: {
|
|
278
|
+
const {queries: queriesToClear} = action
|
|
279
|
+
if (queriesToClear.length === 0) {
|
|
280
|
+
return state
|
|
281
|
+
}
|
|
282
|
+
let newStatesByQueryKey
|
|
283
|
+
const copiedQueryKeys = mutable ? undefined : new Set()
|
|
284
|
+
for (const {query: queryKey, cacheKey} of queriesToClear) {
|
|
285
|
+
const statesByCacheKey = (
|
|
286
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
287
|
+
? newStatesByQueryKey
|
|
288
|
+
: state.queries
|
|
289
|
+
)[queryKey]
|
|
290
|
+
if (cacheKey != null) {
|
|
291
|
+
if (!statesByCacheKey[cacheKey]) {
|
|
292
|
+
continue
|
|
293
|
+
}
|
|
294
|
+
if (mutable) {
|
|
295
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
296
|
+
? newStatesByQueryKey
|
|
297
|
+
: (newStatesByQueryKey = state.queries)
|
|
298
|
+
incrementChangeKey(newStatesByQueryKey[queryKey])
|
|
299
|
+
} else {
|
|
300
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
301
|
+
? newStatesByQueryKey
|
|
302
|
+
: (newStatesByQueryKey = Object.assign({}, state.queries))
|
|
303
|
+
if (!copiedQueryKeys.has(queryKey)) {
|
|
304
|
+
newStatesByQueryKey[queryKey] = Object.assign({}, newStatesByQueryKey[queryKey])
|
|
305
|
+
copiedQueryKeys.add(queryKey)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
delete newStatesByQueryKey[queryKey][cacheKey]
|
|
309
|
+
} else if (mutable) {
|
|
310
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
311
|
+
? newStatesByQueryKey
|
|
312
|
+
: (newStatesByQueryKey = state.queries)
|
|
313
|
+
newStatesByQueryKey[queryKey] = {}
|
|
314
|
+
} else if (statesByCacheKey !== EMPTY_OBJECT) {
|
|
315
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
316
|
+
? newStatesByQueryKey
|
|
317
|
+
: (newStatesByQueryKey = Object.assign({}, state.queries))
|
|
318
|
+
newStatesByQueryKey[queryKey] = EMPTY_OBJECT
|
|
319
|
+
copiedQueryKeys.add(queryKey)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (newStatesByQueryKey === undefined) {
|
|
323
|
+
return state
|
|
324
|
+
}
|
|
325
|
+
if (mutable) {
|
|
326
|
+
incrementChangeKey(newStatesByQueryKey)
|
|
327
|
+
}
|
|
328
|
+
return Object.assign(Object.assign({}, state), {queries: newStatesByQueryKey})
|
|
329
|
+
}
|
|
330
|
+
case clearMutationState.type: {
|
|
331
|
+
const {mutationKeys} = action
|
|
332
|
+
if (mutationKeys.length === 0) {
|
|
333
|
+
return state
|
|
334
|
+
}
|
|
335
|
+
let newMutations = undefined
|
|
336
|
+
for (const mutation of mutationKeys) {
|
|
337
|
+
if (state.mutations[mutation]) {
|
|
338
|
+
newMutations !== null && newMutations !== void 0
|
|
339
|
+
? newMutations
|
|
340
|
+
: (newMutations = mutable ? state.mutations : Object.assign({}, state.mutations))
|
|
341
|
+
delete newMutations[mutation]
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (newMutations === undefined) {
|
|
345
|
+
return state
|
|
346
|
+
}
|
|
347
|
+
if (mutable) {
|
|
348
|
+
incrementChangeKey(newMutations)
|
|
294
349
|
}
|
|
295
|
-
return state
|
|
296
|
-
|
|
297
|
-
|
|
350
|
+
return Object.assign(Object.assign({}, state), {mutations: newMutations})
|
|
351
|
+
}
|
|
352
|
+
case clearCache.type: {
|
|
353
|
+
const {stateToKeep} = action
|
|
354
|
+
const initialState = mutable ? getMutableInitialState() : immutableInitialState
|
|
355
|
+
return stateToKeep ? Object.assign(Object.assign({}, initialState), stateToKeep) : initialState
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return state
|
|
359
|
+
}
|
|
360
|
+
}
|