react-redux-cache 0.22.0 → 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 +0 -1
- package/dist/cjs/createCache.js +4 -5
- package/dist/cjs/createReducer.js +18 -10
- package/dist/cjs/createSelectors.js +2 -3
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/mutate.js +4 -5
- package/dist/cjs/query.js +6 -7
- package/dist/cjs/useMutation.js +13 -3
- package/dist/cjs/useQuery.js +20 -6
- package/dist/cjs/utilsAndConstants.js +3 -3
- package/dist/esm/createCache.js +3 -3
- package/dist/esm/createReducer.js +21 -13
- package/dist/esm/createSelectors.js +2 -2
- package/dist/esm/index.js +0 -2
- package/dist/esm/mutate.js +4 -4
- package/dist/esm/query.js +6 -6
- package/dist/esm/useMutation.js +1 -1
- package/dist/esm/useQuery.js +4 -4
- package/dist/esm/utilsAndConstants.js +2 -2
- package/dist/types/createActions.d.ts +9 -7
- package/dist/types/createCache.d.ts +67 -63
- package/dist/types/createReducer.d.ts +2 -2
- package/dist/types/createSelectors.d.ts +14 -14
- package/dist/types/index.d.ts +0 -2
- package/dist/types/mutate.d.ts +11 -11
- package/dist/types/query.d.ts +14 -14
- package/dist/types/types.d.ts +15 -15
- package/dist/types/useMutation.d.ts +4 -4
- package/dist/types/useQuery.d.ts +4 -4
- package/dist/types/utilsAndConstants.d.ts +3 -3
- package/package.json +12 -13
package/README.md
CHANGED
|
@@ -333,8 +333,8 @@ For huge collections (> 1000 items, see benchmark) immutable approach may be a b
|
|
|
333
333
|
|
|
334
334
|
| Collection size | 0 | 1000 | 10000 | 100000 | 1000000 |
|
|
335
335
|
|-|-|-|-|-|-|
|
|
336
|
-
| immutable | 1.
|
|
337
|
-
| mutable | 1.
|
|
336
|
+
| immutable | 1.57 | 1.81 | 7.62 | 103.82 | 1457.89 |
|
|
337
|
+
| mutable | 1.4 | 1.15 | 0.65 | 1.03 | 0.76 |
|
|
338
338
|
|
|
339
339
|
Well written code should not subcribe to whole collections, so just enabling this options most of the times should not break anything. But if it is still needed, you should subscribe to both collection (it may still change e.g. when clearing state) and to its `_changeKey`.
|
|
340
340
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
3
|
exports.createActions = void 0
|
|
4
4
|
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
5
|
-
|
|
6
5
|
const createActions = (name) => {
|
|
7
6
|
const actionPrefix = `@${utilsAndConstants_1.PACKAGE_SHORT_NAME}/${name}/`
|
|
8
7
|
const updateQueryStateAndEntitiesType = `${actionPrefix}updateQueryStateAndEntities`
|
package/dist/cjs/createCache.js
CHANGED
|
@@ -10,7 +10,6 @@ const query_1 = require('./query')
|
|
|
10
10
|
const useMutation_1 = require('./useMutation')
|
|
11
11
|
const useQuery_1 = require('./useQuery')
|
|
12
12
|
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
13
|
-
|
|
14
13
|
const withTypenames = () => {
|
|
15
14
|
return {
|
|
16
15
|
createCache: (partialCache) => {
|
|
@@ -58,7 +57,7 @@ const withTypenames = () => {
|
|
|
58
57
|
if (cache.options.deepComparisonEnabled && !utilsAndConstants_1.optionalUtils.deepEqual) {
|
|
59
58
|
;(0, utilsAndConstants_1.logWarn)(
|
|
60
59
|
'createCache',
|
|
61
|
-
'optional dependency for fast-deep-equal was not provided, while deepComparisonEnabled option is true'
|
|
60
|
+
'optional dependency for fast-deep-equal was not provided, while deepComparisonEnabled option is true',
|
|
62
61
|
)
|
|
63
62
|
}
|
|
64
63
|
const setDefaultComparer = (target) => {
|
|
@@ -75,7 +74,7 @@ const withTypenames = () => {
|
|
|
75
74
|
}
|
|
76
75
|
const selectors = Object.assign(
|
|
77
76
|
{selectCacheState: cache.cacheStateSelector},
|
|
78
|
-
(0, createSelectors_1.createSelectors)(cache)
|
|
77
|
+
(0, createSelectors_1.createSelectors)(cache),
|
|
79
78
|
)
|
|
80
79
|
const {
|
|
81
80
|
selectCacheState,
|
|
@@ -130,7 +129,7 @@ const withTypenames = () => {
|
|
|
130
129
|
options.mergeResults,
|
|
131
130
|
options.onCompleted,
|
|
132
131
|
options.onSuccess,
|
|
133
|
-
options.onError
|
|
132
|
+
options.onError,
|
|
134
133
|
)
|
|
135
134
|
},
|
|
136
135
|
mutate: (options) => {
|
|
@@ -145,7 +144,7 @@ const withTypenames = () => {
|
|
|
145
144
|
abortControllers,
|
|
146
145
|
options.onCompleted,
|
|
147
146
|
options.onSuccess,
|
|
148
|
-
options.onError
|
|
147
|
+
options.onError,
|
|
149
148
|
)
|
|
150
149
|
},
|
|
151
150
|
}
|
|
@@ -3,12 +3,18 @@ var __rest =
|
|
|
3
3
|
(this && this.__rest) ||
|
|
4
4
|
function (s, e) {
|
|
5
5
|
var t = {}
|
|
6
|
-
for (var p in s) {
|
|
7
|
-
|
|
8
|
-
|
|
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') {
|
|
9
12
|
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
10
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
13
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) {
|
|
14
|
+
t[p[i]] = s[p[i]]
|
|
15
|
+
}
|
|
11
16
|
}
|
|
17
|
+
}
|
|
12
18
|
return t
|
|
13
19
|
}
|
|
14
20
|
Object.defineProperty(exports, '__esModule', {value: true})
|
|
@@ -19,7 +25,7 @@ const optionalMutationKeys = ['error', 'result', 'params', 'loading']
|
|
|
19
25
|
const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
20
26
|
const mutable = cacheOptions.mutableCollections
|
|
21
27
|
cacheOptions.logsEnabled &&
|
|
22
|
-
(0, utilsAndConstants_1.logDebug)('
|
|
28
|
+
(0, utilsAndConstants_1.logDebug)('createReducer', {
|
|
23
29
|
queryKeys,
|
|
24
30
|
mutable,
|
|
25
31
|
})
|
|
@@ -43,7 +49,7 @@ const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
43
49
|
queryKeys.reduce((result, x) => {
|
|
44
50
|
result[x] = Object.freeze({})
|
|
45
51
|
return result
|
|
46
|
-
}, {})
|
|
52
|
+
}, {}),
|
|
47
53
|
),
|
|
48
54
|
mutations: Object.freeze({}),
|
|
49
55
|
})
|
|
@@ -92,7 +98,7 @@ const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
92
98
|
oldQueryState !== null && oldQueryState !== void 0
|
|
93
99
|
? oldQueryState
|
|
94
100
|
: utilsAndConstants_1.EMPTY_OBJECT,
|
|
95
|
-
newQueryState
|
|
101
|
+
newQueryState,
|
|
96
102
|
)
|
|
97
103
|
) {
|
|
98
104
|
newQueryState = undefined
|
|
@@ -119,7 +125,8 @@ const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
119
125
|
[queryCacheKey]: newQueryState,
|
|
120
126
|
}),
|
|
121
127
|
})
|
|
122
|
-
}
|
|
128
|
+
}
|
|
129
|
+
} else if (oldQueryState !== undefined) {
|
|
123
130
|
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
124
131
|
if (mutable) {
|
|
125
132
|
delete newState.queries[queryKey][queryCacheKey]
|
|
@@ -170,7 +177,7 @@ const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
170
177
|
oldMutationState !== null && oldMutationState !== void 0
|
|
171
178
|
? oldMutationState
|
|
172
179
|
: utilsAndConstants_1.EMPTY_OBJECT,
|
|
173
|
-
newMutationState
|
|
180
|
+
newMutationState,
|
|
174
181
|
)
|
|
175
182
|
) {
|
|
176
183
|
newMutationState = undefined
|
|
@@ -193,7 +200,8 @@ const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
193
200
|
newState.mutations = Object.assign(Object.assign({}, state.mutations), {
|
|
194
201
|
[mutationKey]: newMutationState,
|
|
195
202
|
})
|
|
196
|
-
}
|
|
203
|
+
}
|
|
204
|
+
} else if (oldMutationState !== undefined) {
|
|
197
205
|
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
198
206
|
if (mutable) {
|
|
199
207
|
delete state.mutations[mutationKey]
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
3
|
exports.createSelectors = void 0
|
|
4
4
|
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
5
|
-
|
|
6
5
|
const createSelectors = (cache) => {
|
|
7
6
|
const selectEntityById = (state, id, typename) => {
|
|
8
7
|
var _a
|
|
9
8
|
return id == null
|
|
10
9
|
? undefined
|
|
11
10
|
: (_a = cache.cacheStateSelector(state).entities[typename]) === null || _a === void 0
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
? void 0
|
|
12
|
+
: _a[id]
|
|
14
13
|
}
|
|
15
14
|
const selectQueryState = (state, query, cacheKey) => {
|
|
16
15
|
var _a
|
package/dist/cjs/index.js
CHANGED
|
@@ -42,7 +42,6 @@ exports.noop =
|
|
|
42
42
|
exports.createCache =
|
|
43
43
|
void 0
|
|
44
44
|
var createCache_1 = require('./createCache')
|
|
45
|
-
|
|
46
45
|
Object.defineProperty(exports, 'createCache', {
|
|
47
46
|
enumerable: true,
|
|
48
47
|
get() {
|
|
@@ -57,7 +56,6 @@ Object.defineProperty(exports, 'withTypenames', {
|
|
|
57
56
|
})
|
|
58
57
|
__exportStar(require('./types'), exports)
|
|
59
58
|
var utilsAndConstants_1 = require('./utilsAndConstants')
|
|
60
|
-
|
|
61
59
|
Object.defineProperty(exports, 'createStateComparer', {
|
|
62
60
|
enumerable: true,
|
|
63
61
|
get() {
|
package/dist/cjs/mutate.js
CHANGED
|
@@ -33,7 +33,6 @@ var __awaiter =
|
|
|
33
33
|
Object.defineProperty(exports, '__esModule', {value: true})
|
|
34
34
|
exports.mutate = void 0
|
|
35
35
|
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
36
|
-
|
|
37
36
|
const mutate = (
|
|
38
37
|
logTag_1,
|
|
39
38
|
store_1,
|
|
@@ -70,7 +69,7 @@ const mutate = (
|
|
|
70
69
|
abortControllers,
|
|
71
70
|
onCompleted = cache.mutations[mutationKey].onCompleted,
|
|
72
71
|
onSuccess = cache.mutations[mutationKey].onSuccess,
|
|
73
|
-
onError = cache.mutations[mutationKey].onError
|
|
72
|
+
onError = cache.mutations[mutationKey].onError,
|
|
74
73
|
) {
|
|
75
74
|
var _a, _b
|
|
76
75
|
const {updateMutationStateAndEntities} = actions
|
|
@@ -99,7 +98,7 @@ const mutate = (
|
|
|
99
98
|
loading: mutatePromise,
|
|
100
99
|
params,
|
|
101
100
|
result: undefined,
|
|
102
|
-
})
|
|
101
|
+
}),
|
|
103
102
|
)
|
|
104
103
|
let response
|
|
105
104
|
let error
|
|
@@ -123,7 +122,7 @@ const mutate = (
|
|
|
123
122
|
updateMutationStateAndEntities(mutationKey, {
|
|
124
123
|
error,
|
|
125
124
|
loading: undefined,
|
|
126
|
-
})
|
|
125
|
+
}),
|
|
127
126
|
)
|
|
128
127
|
if (
|
|
129
128
|
!(onError === null || onError === void 0
|
|
@@ -155,7 +154,7 @@ const mutate = (
|
|
|
155
154
|
return {result: response.result}
|
|
156
155
|
}
|
|
157
156
|
throw new Error(`${logTag}: both error and response are not defined`)
|
|
158
|
-
}
|
|
157
|
+
},
|
|
159
158
|
)
|
|
160
159
|
exports.mutate = mutate
|
|
161
160
|
const ABORTED_RESULT = Object.freeze({aborted: true})
|
package/dist/cjs/query.js
CHANGED
|
@@ -33,7 +33,6 @@ var __awaiter =
|
|
|
33
33
|
Object.defineProperty(exports, '__esModule', {value: true})
|
|
34
34
|
exports.query = void 0
|
|
35
35
|
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
36
|
-
|
|
37
36
|
const query = (
|
|
38
37
|
logTag,
|
|
39
38
|
store,
|
|
@@ -49,7 +48,7 @@ const query = (
|
|
|
49
48
|
mergeResults,
|
|
50
49
|
onCompleted,
|
|
51
50
|
onSuccess,
|
|
52
|
-
onError
|
|
51
|
+
onError,
|
|
53
52
|
) =>
|
|
54
53
|
__awaiter(void 0, void 0, void 0, function* () {
|
|
55
54
|
var _a, _b, _c, _d
|
|
@@ -110,7 +109,7 @@ const query = (
|
|
|
110
109
|
updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
111
110
|
loading: fetchPromise,
|
|
112
111
|
params,
|
|
113
|
-
})
|
|
112
|
+
}),
|
|
114
113
|
)
|
|
115
114
|
logsEnabled &&
|
|
116
115
|
(0, utilsAndConstants_1.logDebug)(`${logTag} started`, {
|
|
@@ -128,7 +127,7 @@ const query = (
|
|
|
128
127
|
updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
129
128
|
error,
|
|
130
129
|
loading: undefined,
|
|
131
|
-
})
|
|
130
|
+
}),
|
|
132
131
|
)
|
|
133
132
|
if (!(onError === null || onError === void 0 ? void 0 : onError(error, params, store))) {
|
|
134
133
|
;(_c = (_b = cache.globals).onError) === null || _c === void 0
|
|
@@ -147,8 +146,8 @@ const query = (
|
|
|
147
146
|
(_d = response.expiresAt) !== null && _d !== void 0
|
|
148
147
|
? _d
|
|
149
148
|
: secondsToLive != null
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
? Date.now() + secondsToLive * 1000
|
|
150
|
+
: undefined,
|
|
152
151
|
result: mergeResults
|
|
153
152
|
? mergeResults(
|
|
154
153
|
selectQueryResult(store.getState(), queryKey, cacheKey),
|
|
@@ -156,7 +155,7 @@ const query = (
|
|
|
156
155
|
params,
|
|
157
156
|
store,
|
|
158
157
|
actions,
|
|
159
|
-
selectors
|
|
158
|
+
selectors,
|
|
160
159
|
)
|
|
161
160
|
: response.result,
|
|
162
161
|
}
|
package/dist/cjs/useMutation.js
CHANGED
|
@@ -35,7 +35,6 @@ exports.useMutation = void 0
|
|
|
35
35
|
const react_1 = require('react')
|
|
36
36
|
const mutate_1 = require('./mutate')
|
|
37
37
|
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
38
|
-
|
|
39
38
|
const useMutation = (cache, actions, selectors, options, abortControllers) => {
|
|
40
39
|
var _a
|
|
41
40
|
const {selectMutationState} = selectors
|
|
@@ -47,8 +46,19 @@ const useMutation = (cache, actions, selectors, options, abortControllers) => {
|
|
|
47
46
|
(state) => selectMutationState(state, mutationKey),
|
|
48
47
|
(params) =>
|
|
49
48
|
__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
return yield (0,
|
|
51
|
-
|
|
49
|
+
return yield (0, mutate_1.mutate)(
|
|
50
|
+
'useMutation.mutate',
|
|
51
|
+
store,
|
|
52
|
+
cache,
|
|
53
|
+
actions,
|
|
54
|
+
selectors,
|
|
55
|
+
mutationKey,
|
|
56
|
+
params,
|
|
57
|
+
abortControllers,
|
|
58
|
+
onCompleted,
|
|
59
|
+
onSuccess,
|
|
60
|
+
onError,
|
|
61
|
+
)
|
|
52
62
|
}),
|
|
53
63
|
() => {
|
|
54
64
|
var _a
|
package/dist/cjs/useQuery.js
CHANGED
|
@@ -35,7 +35,6 @@ exports.useQuery = void 0
|
|
|
35
35
|
const react_1 = require('react')
|
|
36
36
|
const query_1 = require('./query')
|
|
37
37
|
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
38
|
-
|
|
39
38
|
const useQuery = (cache, actions, selectors, options) => {
|
|
40
39
|
var _a, _b, _c, _d, _e
|
|
41
40
|
const {
|
|
@@ -66,18 +65,33 @@ const useQuery = (cache, actions, selectors, options) => {
|
|
|
66
65
|
? _d
|
|
67
66
|
: defaultStateComparer
|
|
68
67
|
: typeof selectorComparer === 'function'
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
? selectorComparer
|
|
69
|
+
: (0, utilsAndConstants_1.createStateComparer)(selectorComparer)
|
|
71
70
|
const store = cache.storeHooks.useStore()
|
|
72
71
|
const cacheKey = getCacheKey(params)
|
|
73
72
|
const performFetch = (0, react_1.useCallback)(
|
|
74
73
|
(options) =>
|
|
75
74
|
__awaiter(void 0, void 0, void 0, function* () {
|
|
76
75
|
const paramsPassed = options && 'params' in options
|
|
77
|
-
return yield (0,
|
|
78
|
-
|
|
76
|
+
return yield (0, query_1.query)(
|
|
77
|
+
'useQuery.fetch',
|
|
78
|
+
store,
|
|
79
|
+
cache,
|
|
80
|
+
actions,
|
|
81
|
+
selectors,
|
|
82
|
+
queryKey,
|
|
83
|
+
paramsPassed ? getCacheKey(options.params) : cacheKey,
|
|
84
|
+
paramsPassed ? options.params : params,
|
|
85
|
+
secondsToLive,
|
|
86
|
+
options === null || options === void 0 ? void 0 : options.onlyIfExpired,
|
|
87
|
+
false,
|
|
88
|
+
mergeResults,
|
|
89
|
+
onCompleted,
|
|
90
|
+
onSuccess,
|
|
91
|
+
onError,
|
|
92
|
+
)
|
|
79
93
|
}),
|
|
80
|
-
[store, queryKey, cacheKey]
|
|
94
|
+
[store, queryKey, cacheKey],
|
|
81
95
|
)
|
|
82
96
|
const queryState =
|
|
83
97
|
(_e = cache.storeHooks.useSelector((state) => {
|
|
@@ -35,7 +35,7 @@ try {
|
|
|
35
35
|
exports.IS_DEV = (() => {
|
|
36
36
|
try {
|
|
37
37
|
return __DEV__
|
|
38
|
-
} catch (
|
|
38
|
+
} catch (_a) {
|
|
39
39
|
return process.env.NODE_ENV === 'development'
|
|
40
40
|
}
|
|
41
41
|
})()
|
|
@@ -69,7 +69,7 @@ const applyEntityChanges = (entities, changes, options) => {
|
|
|
69
69
|
let result
|
|
70
70
|
const objectWithAllTypenames = Object.assign(
|
|
71
71
|
Object.assign(Object.assign({}, changes.merge), changes.remove),
|
|
72
|
-
changes.replace
|
|
72
|
+
changes.replace,
|
|
73
73
|
)
|
|
74
74
|
for (const typename in objectWithAllTypenames) {
|
|
75
75
|
const entitiesToMerge = merge === null || merge === void 0 ? void 0 : merge[typename]
|
|
@@ -106,7 +106,7 @@ const applyEntityChanges = (entities, changes, options) => {
|
|
|
106
106
|
if (totalKeysInResponse !== 0 && idsSet.size !== totalKeysInResponse) {
|
|
107
107
|
;(0, exports.logWarn)(
|
|
108
108
|
'applyEntityChanges',
|
|
109
|
-
'merge, replace and remove changes have intersections for: ' + typename
|
|
109
|
+
'merge, replace and remove changes have intersections for: ' + typename,
|
|
110
110
|
)
|
|
111
111
|
}
|
|
112
112
|
}
|
package/dist/esm/createCache.js
CHANGED
|
@@ -65,7 +65,7 @@ export const withTypenames = () => {
|
|
|
65
65
|
if (cache.options.deepComparisonEnabled && !optionalUtils.deepEqual) {
|
|
66
66
|
logWarn(
|
|
67
67
|
'createCache',
|
|
68
|
-
'optional dependency for fast-deep-equal was not provided, while deepComparisonEnabled option is true'
|
|
68
|
+
'optional dependency for fast-deep-equal was not provided, while deepComparisonEnabled option is true',
|
|
69
69
|
)
|
|
70
70
|
}
|
|
71
71
|
const setDefaultComparer = (target) => {
|
|
@@ -132,7 +132,7 @@ export const withTypenames = () => {
|
|
|
132
132
|
options.mergeResults,
|
|
133
133
|
options.onCompleted,
|
|
134
134
|
options.onSuccess,
|
|
135
|
-
options.onError
|
|
135
|
+
options.onError,
|
|
136
136
|
)
|
|
137
137
|
},
|
|
138
138
|
mutate: (options) => {
|
|
@@ -147,7 +147,7 @@ export const withTypenames = () => {
|
|
|
147
147
|
abortControllers,
|
|
148
148
|
options.onCompleted,
|
|
149
149
|
options.onSuccess,
|
|
150
|
-
options.onError
|
|
150
|
+
options.onError,
|
|
151
151
|
)
|
|
152
152
|
},
|
|
153
153
|
}
|
|
@@ -2,13 +2,18 @@ var __rest =
|
|
|
2
2
|
(this && this.__rest) ||
|
|
3
3
|
function (s, e) {
|
|
4
4
|
var t = {}
|
|
5
|
-
for (var p in s) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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]]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
12
17
|
return t
|
|
13
18
|
}
|
|
14
19
|
import {
|
|
@@ -21,10 +26,11 @@ import {
|
|
|
21
26
|
} from './utilsAndConstants'
|
|
22
27
|
const optionalQueryKeys = ['error', 'expiresAt', 'result', 'params', 'loading']
|
|
23
28
|
const optionalMutationKeys = ['error', 'result', 'params', 'loading']
|
|
29
|
+
|
|
24
30
|
export const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
25
31
|
const mutable = cacheOptions.mutableCollections
|
|
26
32
|
cacheOptions.logsEnabled &&
|
|
27
|
-
logDebug('
|
|
33
|
+
logDebug('createReducer', {
|
|
28
34
|
queryKeys,
|
|
29
35
|
mutable,
|
|
30
36
|
})
|
|
@@ -48,7 +54,7 @@ export const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
48
54
|
queryKeys.reduce((result, x) => {
|
|
49
55
|
result[x] = Object.freeze({})
|
|
50
56
|
return result
|
|
51
|
-
}, {})
|
|
57
|
+
}, {}),
|
|
52
58
|
),
|
|
53
59
|
mutations: Object.freeze({}),
|
|
54
60
|
})
|
|
@@ -93,7 +99,7 @@ export const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
93
99
|
? void 0
|
|
94
100
|
: deepEqual(
|
|
95
101
|
oldQueryState !== null && oldQueryState !== void 0 ? oldQueryState : EMPTY_OBJECT,
|
|
96
|
-
newQueryState
|
|
102
|
+
newQueryState,
|
|
97
103
|
)
|
|
98
104
|
) {
|
|
99
105
|
newQueryState = undefined
|
|
@@ -118,7 +124,8 @@ export const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
118
124
|
[queryCacheKey]: newQueryState,
|
|
119
125
|
}),
|
|
120
126
|
})
|
|
121
|
-
}
|
|
127
|
+
}
|
|
128
|
+
} else if (oldQueryState !== undefined) {
|
|
122
129
|
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
123
130
|
if (mutable) {
|
|
124
131
|
delete newState.queries[queryKey][queryCacheKey]
|
|
@@ -167,7 +174,7 @@ export const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
167
174
|
? void 0
|
|
168
175
|
: deepEqual(
|
|
169
176
|
oldMutationState !== null && oldMutationState !== void 0 ? oldMutationState : EMPTY_OBJECT,
|
|
170
|
-
newMutationState
|
|
177
|
+
newMutationState,
|
|
171
178
|
)
|
|
172
179
|
) {
|
|
173
180
|
newMutationState = undefined
|
|
@@ -188,7 +195,8 @@ export const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
188
195
|
newState.mutations = Object.assign(Object.assign({}, state.mutations), {
|
|
189
196
|
[mutationKey]: newMutationState,
|
|
190
197
|
})
|
|
191
|
-
}
|
|
198
|
+
}
|
|
199
|
+
} else if (oldMutationState !== undefined) {
|
|
192
200
|
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
193
201
|
if (mutable) {
|
|
194
202
|
delete state.mutations[mutationKey]
|
|
@@ -6,8 +6,8 @@ export const createSelectors = (cache) => {
|
|
|
6
6
|
return id == null
|
|
7
7
|
? undefined
|
|
8
8
|
: (_a = cache.cacheStateSelector(state).entities[typename]) === null || _a === void 0
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
? void 0
|
|
10
|
+
: _a[id]
|
|
11
11
|
}
|
|
12
12
|
const selectQueryState = (state, query, cacheKey) => {
|
|
13
13
|
var _a
|
package/dist/esm/index.js
CHANGED
package/dist/esm/mutate.js
CHANGED
|
@@ -67,7 +67,7 @@ export const mutate = (
|
|
|
67
67
|
abortControllers,
|
|
68
68
|
onCompleted = cache.mutations[mutationKey].onCompleted,
|
|
69
69
|
onSuccess = cache.mutations[mutationKey].onSuccess,
|
|
70
|
-
onError = cache.mutations[mutationKey].onError
|
|
70
|
+
onError = cache.mutations[mutationKey].onError,
|
|
71
71
|
) {
|
|
72
72
|
var _a, _b
|
|
73
73
|
const {updateMutationStateAndEntities} = actions
|
|
@@ -92,7 +92,7 @@ export const mutate = (
|
|
|
92
92
|
loading: mutatePromise,
|
|
93
93
|
params,
|
|
94
94
|
result: undefined,
|
|
95
|
-
})
|
|
95
|
+
}),
|
|
96
96
|
)
|
|
97
97
|
let response
|
|
98
98
|
let error
|
|
@@ -112,7 +112,7 @@ export const mutate = (
|
|
|
112
112
|
updateMutationStateAndEntities(mutationKey, {
|
|
113
113
|
error,
|
|
114
114
|
loading: undefined,
|
|
115
|
-
})
|
|
115
|
+
}),
|
|
116
116
|
)
|
|
117
117
|
if (
|
|
118
118
|
!(onError === null || onError === void 0
|
|
@@ -144,7 +144,7 @@ export const mutate = (
|
|
|
144
144
|
return {result: response.result}
|
|
145
145
|
}
|
|
146
146
|
throw new Error(`${logTag}: both error and response are not defined`)
|
|
147
|
-
}
|
|
147
|
+
},
|
|
148
148
|
)
|
|
149
149
|
|
|
150
150
|
const ABORTED_RESULT = Object.freeze({aborted: true})
|
package/dist/esm/query.js
CHANGED
|
@@ -46,7 +46,7 @@ export const query = (
|
|
|
46
46
|
mergeResults,
|
|
47
47
|
onCompleted,
|
|
48
48
|
onSuccess,
|
|
49
|
-
onError
|
|
49
|
+
onError,
|
|
50
50
|
) =>
|
|
51
51
|
__awaiter(void 0, void 0, void 0, function* () {
|
|
52
52
|
var _a, _b, _c, _d
|
|
@@ -103,7 +103,7 @@ export const query = (
|
|
|
103
103
|
updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
104
104
|
loading: fetchPromise,
|
|
105
105
|
params,
|
|
106
|
-
})
|
|
106
|
+
}),
|
|
107
107
|
)
|
|
108
108
|
logsEnabled &&
|
|
109
109
|
logDebug(`${logTag} started`, {queryKey, params, cacheKey, queryStateOnStart, onlyIfExpired})
|
|
@@ -115,7 +115,7 @@ export const query = (
|
|
|
115
115
|
updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
116
116
|
error,
|
|
117
117
|
loading: undefined,
|
|
118
|
-
})
|
|
118
|
+
}),
|
|
119
119
|
)
|
|
120
120
|
if (!(onError === null || onError === void 0 ? void 0 : onError(error, params, store))) {
|
|
121
121
|
;(_c = (_b = cache.globals).onError) === null || _c === void 0
|
|
@@ -134,8 +134,8 @@ export const query = (
|
|
|
134
134
|
(_d = response.expiresAt) !== null && _d !== void 0
|
|
135
135
|
? _d
|
|
136
136
|
: secondsToLive != null
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
? Date.now() + secondsToLive * 1000
|
|
138
|
+
: undefined,
|
|
139
139
|
result: mergeResults
|
|
140
140
|
? mergeResults(
|
|
141
141
|
selectQueryResult(store.getState(), queryKey, cacheKey),
|
|
@@ -143,7 +143,7 @@ export const query = (
|
|
|
143
143
|
params,
|
|
144
144
|
store,
|
|
145
145
|
actions,
|
|
146
|
-
selectors
|
|
146
|
+
selectors,
|
|
147
147
|
)
|
|
148
148
|
: response.result,
|
|
149
149
|
}
|
package/dist/esm/useMutation.js
CHANGED
package/dist/esm/useQuery.js
CHANGED
|
@@ -63,8 +63,8 @@ export const useQuery = (cache, actions, selectors, options) => {
|
|
|
63
63
|
? _d
|
|
64
64
|
: defaultStateComparer
|
|
65
65
|
: typeof selectorComparer === 'function'
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
? selectorComparer
|
|
67
|
+
: createStateComparer(selectorComparer)
|
|
68
68
|
const store = cache.storeHooks.useStore()
|
|
69
69
|
const cacheKey = getCacheKey(params)
|
|
70
70
|
const performFetch = useCallback(
|
|
@@ -86,10 +86,10 @@ export const useQuery = (cache, actions, selectors, options) => {
|
|
|
86
86
|
mergeResults,
|
|
87
87
|
onCompleted,
|
|
88
88
|
onSuccess,
|
|
89
|
-
onError
|
|
89
|
+
onError,
|
|
90
90
|
)
|
|
91
91
|
}),
|
|
92
|
-
[store, queryKey, cacheKey]
|
|
92
|
+
[store, queryKey, cacheKey],
|
|
93
93
|
)
|
|
94
94
|
const queryState =
|
|
95
95
|
(_e = cache.storeHooks.useSelector((state) => {
|
|
@@ -21,7 +21,7 @@ try {
|
|
|
21
21
|
export const IS_DEV = (() => {
|
|
22
22
|
try {
|
|
23
23
|
return __DEV__
|
|
24
|
-
} catch (
|
|
24
|
+
} catch (_a) {
|
|
25
25
|
return process.env.NODE_ENV === 'development'
|
|
26
26
|
}
|
|
27
27
|
})()
|
|
@@ -58,7 +58,7 @@ export const applyEntityChanges = (entities, changes, options) => {
|
|
|
58
58
|
let result
|
|
59
59
|
const objectWithAllTypenames = Object.assign(
|
|
60
60
|
Object.assign(Object.assign({}, changes.merge), changes.remove),
|
|
61
|
-
changes.replace
|
|
61
|
+
changes.replace,
|
|
62
62
|
)
|
|
63
63
|
for (const typename in objectWithAllTypenames) {
|
|
64
64
|
const entitiesToMerge = merge === null || merge === void 0 ? void 0 : merge[typename]
|