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