react-redux-cache 0.21.0 → 0.22.1

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.
@@ -1,272 +1,297 @@
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]]
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
14
9
  }
15
- }
16
- }
17
- return t
18
- }
19
- import {applyEntityChanges, EMPTY_OBJECT, isEmptyObject, logDebug, optionalUtils} from './utilsAndConstants'
20
-
21
- const optionalQueryKeys = ['error', 'expiresAt', 'result', 'params', 'loading']
22
- const optionalMutationKeys = ['error', 'result', 'params', 'loading']
23
-
10
+ return t;
11
+ };
12
+ import { applyEntityChanges, EMPTY_OBJECT, incrementChangeKey, isEmptyObject, logDebug, optionalUtils, } from './utilsAndConstants';
13
+ const optionalQueryKeys = [
14
+ 'error',
15
+ 'expiresAt',
16
+ 'result',
17
+ 'params',
18
+ 'loading',
19
+ ];
20
+ const optionalMutationKeys = [
21
+ 'error',
22
+ 'result',
23
+ 'params',
24
+ 'loading',
25
+ ];
24
26
  export const createReducer = (actions, queryKeys, cacheOptions) => {
25
- const initialState = Object.freeze({
26
- entities: Object.freeze({}),
27
- queries: Object.freeze(
28
- queryKeys.reduce((result, x) => {
29
- result[x] = Object.freeze({})
30
- return result
31
- }, {})
32
- ),
33
- mutations: Object.freeze({}),
34
- })
35
- cacheOptions.logsEnabled &&
36
- logDebug('createCacheReducer', {
37
- queryKeys,
38
- initialState,
39
- })
40
- const deepEqual = cacheOptions.deepComparisonEnabled ? optionalUtils.deepEqual : undefined
41
- return (state = initialState, action) => {
42
- switch (action.type) {
43
- case actions.updateQueryStateAndEntities.type: {
44
- const {queryKey, queryCacheKey, state: queryState, entityChanges} = action
45
- const oldQueryState = state.queries[queryKey][queryCacheKey]
46
- let newQueryState = queryState && Object.assign(Object.assign({}, oldQueryState), queryState)
47
- if (newQueryState) {
48
- if (oldQueryState && deepEqual) {
49
- if (
50
- newQueryState.params !== oldQueryState.params &&
51
- deepEqual(newQueryState.params, oldQueryState.params)
52
- ) {
53
- newQueryState.params = oldQueryState.params
54
- }
55
- if (
56
- newQueryState.result !== oldQueryState.result &&
57
- deepEqual(newQueryState.result, oldQueryState.result)
58
- ) {
59
- newQueryState.result = oldQueryState.result
60
- }
61
- }
62
- for (const key of optionalQueryKeys) {
63
- if (key in newQueryState && newQueryState[key] === undefined) {
64
- delete newQueryState[key]
65
- }
66
- }
67
- if (
68
- deepEqual === null || deepEqual === void 0
69
- ? void 0
70
- : deepEqual(
71
- oldQueryState !== null && oldQueryState !== void 0 ? oldQueryState : EMPTY_OBJECT,
72
- newQueryState
73
- )
74
- ) {
75
- newQueryState = undefined
76
- }
77
- }
78
- const newEntities = entityChanges && applyEntityChanges(state.entities, entityChanges, cacheOptions)
79
- let newState
80
- if (newEntities) {
81
- newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
82
- newState.entities = newEntities
27
+ const mutable = cacheOptions.mutableCollections;
28
+ cacheOptions.logsEnabled &&
29
+ logDebug('createReducer', {
30
+ queryKeys,
31
+ mutable,
32
+ });
33
+ const getMutableInitialState = mutable
34
+ ? () => {
35
+ return {
36
+ entities: {},
37
+ queries: queryKeys.reduce((result, x) => {
38
+ result[x] = {};
39
+ return result;
40
+ }, {}),
41
+ mutations: {},
42
+ };
83
43
  }
84
- if (newQueryState) {
85
- if (!isEmptyObject(newQueryState)) {
86
- newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
87
- newState.queries = Object.assign(Object.assign({}, state.queries), {
88
- [queryKey]: Object.assign(Object.assign({}, state.queries[queryKey]), {
89
- [queryCacheKey]: newQueryState,
90
- }),
91
- })
92
- } else if (oldQueryState !== undefined) {
93
- const _a = state.queries[queryKey],
94
- _b = queryCacheKey,
95
- _ = _a[_b],
96
- withoutCacheKey = __rest(_a, [typeof _b === 'symbol' ? _b : _b + ''])
97
- newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
98
- newState.queries = Object.assign(Object.assign({}, state.queries), {[queryKey]: withoutCacheKey})
99
- }
100
- }
101
- return newState !== null && newState !== void 0 ? newState : state
102
- }
103
- case actions.updateMutationStateAndEntities.type: {
104
- const {mutationKey, state: mutationState, entityChanges} = action
105
- const oldMutationState = state.mutations[mutationKey]
106
- let newMutationState =
107
- mutationState && Object.assign(Object.assign({}, oldMutationState), mutationState)
108
- if (newMutationState) {
109
- if (oldMutationState && deepEqual) {
110
- if (
111
- newMutationState.params !== oldMutationState.params &&
112
- deepEqual(newMutationState.params, oldMutationState.params)
113
- ) {
114
- newMutationState.params = oldMutationState.params
44
+ : undefined;
45
+ const immutableInitialState = mutable
46
+ ? undefined
47
+ : Object.freeze({
48
+ entities: Object.freeze({}),
49
+ queries: Object.freeze(queryKeys.reduce((result, x) => {
50
+ result[x] = Object.freeze({});
51
+ return result;
52
+ }, {})),
53
+ mutations: Object.freeze({}),
54
+ });
55
+ const { clearCache, clearMutationState, clearQueryState, invalidateQuery, mergeEntityChanges, updateMutationStateAndEntities, updateQueryStateAndEntities, } = actions;
56
+ const deepEqual = cacheOptions.deepComparisonEnabled ? optionalUtils.deepEqual : undefined;
57
+ return (state = mutable ? getMutableInitialState() : immutableInitialState, action) => {
58
+ switch (action.type) {
59
+ case updateQueryStateAndEntities.type: {
60
+ const { queryKey, queryCacheKey, state: queryState, entityChanges, } = action;
61
+ const oldQueryState = state.queries[queryKey][queryCacheKey];
62
+ let newQueryState = queryState && Object.assign(Object.assign({}, oldQueryState), queryState);
63
+ if (newQueryState) {
64
+ if (oldQueryState && deepEqual) {
65
+ if (newQueryState.params !== oldQueryState.params &&
66
+ deepEqual(newQueryState.params, oldQueryState.params)) {
67
+ newQueryState.params = oldQueryState.params;
68
+ }
69
+ if (newQueryState.result !== oldQueryState.result &&
70
+ deepEqual(newQueryState.result, oldQueryState.result)) {
71
+ newQueryState.result = oldQueryState.result;
72
+ }
73
+ }
74
+ for (const key of optionalQueryKeys) {
75
+ if (key in newQueryState && newQueryState[key] === undefined) {
76
+ delete newQueryState[key];
77
+ }
78
+ }
79
+ if (deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldQueryState !== null && oldQueryState !== void 0 ? oldQueryState : EMPTY_OBJECT, newQueryState)) {
80
+ newQueryState = undefined;
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;
115
115
  }
116
- if (
117
- newMutationState.result !== oldMutationState.result &&
118
- deepEqual(newMutationState.result, oldMutationState.result)
119
- ) {
120
- newMutationState.result = oldMutationState.result
116
+ case updateMutationStateAndEntities.type: {
117
+ const { mutationKey, state: mutationState, entityChanges, } = action;
118
+ const oldMutationState = state.mutations[mutationKey];
119
+ let newMutationState = mutationState && Object.assign(Object.assign({}, oldMutationState), mutationState);
120
+ if (newMutationState) {
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;
121
169
  }
122
- }
123
- for (const key of optionalMutationKeys) {
124
- if (key in newMutationState && newMutationState[key] === undefined) {
125
- delete newMutationState[key]
170
+ case mergeEntityChanges.type: {
171
+ const { changes } = action;
172
+ const newEntities = applyEntityChanges(state.entities, changes, cacheOptions);
173
+ return newEntities ? Object.assign(Object.assign({}, state), { entities: newEntities }) : state;
126
174
  }
127
- }
128
- if (
129
- deepEqual === null || deepEqual === void 0
130
- ? void 0
131
- : deepEqual(
132
- oldMutationState !== null && oldMutationState !== void 0 ? oldMutationState : EMPTY_OBJECT,
133
- newMutationState
134
- )
135
- ) {
136
- newMutationState = undefined
137
- }
138
- }
139
- const newEntities = entityChanges && applyEntityChanges(state.entities, entityChanges, cacheOptions)
140
- let newState
141
- if (newEntities) {
142
- newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
143
- newState.entities = newEntities
144
- }
145
- if (newMutationState) {
146
- if (!isEmptyObject(newMutationState)) {
147
- newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
148
- newState.mutations = Object.assign(Object.assign({}, state.mutations), {
149
- [mutationKey]: newMutationState,
150
- })
151
- } else if (oldMutationState !== undefined) {
152
- const _c = state.mutations,
153
- _d = mutationKey,
154
- _ = _c[_d],
155
- withoutMutationKey = __rest(_c, [typeof _d === 'symbol' ? _d : _d + ''])
156
- newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
157
- newState.mutations = withoutMutationKey
158
- }
159
- }
160
- return newState !== null && newState !== void 0 ? newState : state
161
- }
162
- case actions.mergeEntityChanges.type: {
163
- const {changes} = action
164
- const newEntities = applyEntityChanges(state.entities, changes, cacheOptions)
165
- return newEntities ? Object.assign(Object.assign({}, state), {entities: newEntities}) : state
166
- }
167
- case actions.invalidateQuery.type: {
168
- const {queries: queriesToInvalidate} = action
169
- if (queriesToInvalidate.length === 0) {
170
- return state
171
- }
172
- const now = Date.now()
173
- let newQueries = undefined
174
- for (const {query: queryKey, cacheKey, expiresAt = now} of queriesToInvalidate) {
175
- const queryStates = (newQueries !== null && newQueries !== void 0 ? newQueries : state.queries)[
176
- queryKey
177
- ]
178
- if (cacheKey != null) {
179
- if (queryStates[cacheKey]) {
180
- const queryState = queryStates[cacheKey]
181
- if (queryState && queryState.expiresAt !== expiresAt) {
182
- newQueries !== null && newQueries !== void 0
183
- ? newQueries
184
- : (newQueries = Object.assign({}, state.queries))
185
- if (state.queries[queryKey] === newQueries[queryKey]) {
186
- newQueries[queryKey] = Object.assign({}, newQueries[queryKey])
175
+ case invalidateQuery.type: {
176
+ const { queries: queriesToInvalidate } = action;
177
+ if (queriesToInvalidate.length === 0) {
178
+ return state;
179
+ }
180
+ const now = Date.now();
181
+ let newStatesByQueryKey;
182
+ const copiedQueryKeys = mutable ? undefined : new Set();
183
+ for (const { query: queryKey, cacheKey, expiresAt = now } of queriesToInvalidate) {
184
+ const statesByCacheKey = (newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : state.queries)[queryKey];
185
+ const cacheKeysToInvalidate = cacheKey != null ? [cacheKey] : Object.keys(statesByCacheKey);
186
+ for (const cacheKey of cacheKeysToInvalidate) {
187
+ const queryState = statesByCacheKey[cacheKey];
188
+ if (!queryState || queryState.expiresAt === expiresAt) {
189
+ continue;
190
+ }
191
+ if (mutable) {
192
+ newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = state.queries);
193
+ incrementChangeKey(newStatesByQueryKey[queryKey]);
194
+ }
195
+ else {
196
+ newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = Object.assign({}, state.queries));
197
+ if (!copiedQueryKeys.has(queryKey)) {
198
+ newStatesByQueryKey[queryKey] = Object.assign({}, newStatesByQueryKey[queryKey]);
199
+ copiedQueryKeys.add(queryKey);
200
+ }
201
+ }
202
+ if (expiresAt !== undefined) {
203
+ newStatesByQueryKey[queryKey][cacheKey] = Object.assign(Object.assign({}, queryState), { expiresAt });
204
+ }
205
+ else {
206
+ const { expiresAt: _ } = queryState, newQueryState = __rest(queryState, ["expiresAt"]);
207
+ if (isEmptyObject(newQueryState)) {
208
+ delete newStatesByQueryKey[queryKey][cacheKey];
209
+ }
210
+ else {
211
+ newStatesByQueryKey[queryKey][cacheKey] = newQueryState;
212
+ }
213
+ }
214
+ }
187
215
  }
188
- newQueries[queryKey][cacheKey] = Object.assign(Object.assign({}, queryState), {expiresAt})
189
- if (expiresAt === undefined) {
190
- delete newQueries[queryKey][cacheKey].expiresAt
216
+ if (!newStatesByQueryKey) {
217
+ return state;
191
218
  }
192
- }
219
+ if (mutable) {
220
+ incrementChangeKey(newStatesByQueryKey);
221
+ }
222
+ return Object.assign(Object.assign({}, state), { queries: newStatesByQueryKey });
193
223
  }
194
- } else {
195
- for (const cacheKey in queryStates) {
196
- const queryState = queryStates[cacheKey]
197
- if (queryState && queryState.expiresAt !== expiresAt) {
198
- newQueries !== null && newQueries !== void 0
199
- ? newQueries
200
- : (newQueries = Object.assign({}, state.queries))
201
- if (state.queries[queryKey] === newQueries[queryKey]) {
202
- newQueries[queryKey] = Object.assign({}, newQueries[queryKey])
224
+ case clearQueryState.type: {
225
+ const { queries: queriesToClear } = action;
226
+ if (queriesToClear.length === 0) {
227
+ return state;
228
+ }
229
+ let newStatesByQueryKey;
230
+ const copiedQueryKeys = mutable ? undefined : new Set();
231
+ for (const { query: queryKey, cacheKey } of queriesToClear) {
232
+ const statesByCacheKey = (newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : state.queries)[queryKey];
233
+ if (cacheKey != null) {
234
+ if (!statesByCacheKey[cacheKey]) {
235
+ continue;
236
+ }
237
+ if (mutable) {
238
+ newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = state.queries);
239
+ incrementChangeKey(newStatesByQueryKey[queryKey]);
240
+ }
241
+ else {
242
+ newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = Object.assign({}, state.queries));
243
+ if (!copiedQueryKeys.has(queryKey)) {
244
+ newStatesByQueryKey[queryKey] = Object.assign({}, newStatesByQueryKey[queryKey]);
245
+ copiedQueryKeys.add(queryKey);
246
+ }
247
+ }
248
+ delete newStatesByQueryKey[queryKey][cacheKey];
249
+ }
250
+ else if (mutable) {
251
+ newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = state.queries);
252
+ newStatesByQueryKey[queryKey] = {};
253
+ }
254
+ else if (statesByCacheKey !== EMPTY_OBJECT) {
255
+ newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = Object.assign({}, state.queries));
256
+ newStatesByQueryKey[queryKey] = EMPTY_OBJECT;
257
+ copiedQueryKeys.add(queryKey);
258
+ }
203
259
  }
204
- newQueries[queryKey][cacheKey] = Object.assign(Object.assign({}, queryState), {expiresAt})
205
- if (expiresAt === undefined) {
206
- delete newQueries[queryKey][cacheKey].expiresAt
260
+ if (newStatesByQueryKey === undefined) {
261
+ return state;
207
262
  }
208
- }
263
+ if (mutable) {
264
+ incrementChangeKey(newStatesByQueryKey);
265
+ }
266
+ return Object.assign(Object.assign({}, state), { queries: newStatesByQueryKey });
209
267
  }
210
- }
211
- }
212
- return newQueries === undefined
213
- ? state
214
- : Object.assign(Object.assign({}, state), {queries: newQueries})
215
- }
216
- case actions.clearQueryState.type: {
217
- const {queries: queriesToClear} = action
218
- if (queriesToClear.length === 0) {
219
- return state
220
- }
221
- let newQueries = undefined
222
- for (const {query: queryKey, cacheKey} of queriesToClear) {
223
- const queryStates = (newQueries !== null && newQueries !== void 0 ? newQueries : state.queries)[
224
- queryKey
225
- ]
226
- if (cacheKey != null) {
227
- if (queryStates[cacheKey]) {
228
- newQueries !== null && newQueries !== void 0
229
- ? newQueries
230
- : (newQueries = Object.assign({}, state.queries))
231
- if (state.queries[queryKey] === newQueries[queryKey]) {
232
- newQueries[queryKey] = Object.assign({}, newQueries[queryKey])
233
- }
234
- delete newQueries[queryKey][cacheKey]
268
+ case clearMutationState.type: {
269
+ const { mutationKeys } = action;
270
+ if (mutationKeys.length === 0) {
271
+ return state;
272
+ }
273
+ let newMutations = undefined;
274
+ for (const mutation of mutationKeys) {
275
+ if (state.mutations[mutation]) {
276
+ newMutations !== null && newMutations !== void 0 ? newMutations : (newMutations = mutable ? state.mutations : Object.assign({}, state.mutations));
277
+ delete newMutations[mutation];
278
+ }
279
+ }
280
+ if (newMutations === undefined) {
281
+ return state;
282
+ }
283
+ if (mutable) {
284
+ incrementChangeKey(newMutations);
285
+ }
286
+ return Object.assign(Object.assign({}, state), { mutations: newMutations });
287
+ }
288
+ case clearCache.type: {
289
+ const { stateToKeep } = action;
290
+ const initialState = mutable ? getMutableInitialState() : immutableInitialState;
291
+ return stateToKeep
292
+ ? Object.assign(Object.assign({}, initialState), stateToKeep) : initialState;
235
293
  }
236
- } else if (queryStates !== EMPTY_OBJECT) {
237
- newQueries !== null && newQueries !== void 0
238
- ? newQueries
239
- : (newQueries = Object.assign({}, state.queries))
240
- newQueries[queryKey] = EMPTY_OBJECT
241
- }
242
- }
243
- return newQueries === undefined
244
- ? state
245
- : Object.assign(Object.assign({}, state), {queries: newQueries})
246
- }
247
- case actions.clearMutationState.type: {
248
- const {mutationKeys} = action
249
- if (mutationKeys.length === 0) {
250
- return state
251
- }
252
- let newMutations = undefined
253
- for (const mutation of mutationKeys) {
254
- if (state.mutations[mutation]) {
255
- newMutations !== null && newMutations !== void 0
256
- ? newMutations
257
- : (newMutations = Object.assign({}, state.mutations))
258
- delete newMutations[mutation]
259
- }
260
294
  }
261
- return newMutations === undefined
262
- ? state
263
- : Object.assign(Object.assign({}, state), {mutations: newMutations})
264
- }
265
- case actions.clearCache.type: {
266
- const {stateToKeep} = action
267
- return stateToKeep ? Object.assign(Object.assign({}, initialState), stateToKeep) : initialState
268
- }
269
- }
270
- return state
271
- }
272
- }
295
+ return state;
296
+ };
297
+ };