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