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.
- package/README.md +36 -2
- package/dist/cjs/createActions.js +63 -64
- package/dist/cjs/createCache.js +132 -204
- package/dist/cjs/createReducer.js +287 -271
- package/dist/cjs/createSelectors.js +58 -67
- package/dist/cjs/index.js +26 -89
- package/dist/cjs/mutate.js +69 -153
- package/dist/cjs/query.js +70 -162
- package/dist/cjs/types.js +2 -2
- package/dist/cjs/useMutation.js +42 -71
- package/dist/cjs/useQuery.js +56 -113
- package/dist/cjs/utilsAndConstants.js +151 -175
- package/dist/esm/createActions.js +59 -60
- package/dist/esm/createCache.js +128 -205
- package/dist/esm/createReducer.js +283 -258
- package/dist/esm/createSelectors.js +54 -63
- package/dist/esm/index.js +3 -5
- package/dist/esm/mutate.js +65 -142
- package/dist/esm/query.js +66 -149
- package/dist/esm/types.js +1 -1
- package/dist/esm/useMutation.js +38 -77
- package/dist/esm/useQuery.js +52 -119
- package/dist/esm/utilsAndConstants.js +140 -162
- package/dist/types/createActions.d.ts +83 -107
- package/dist/types/createCache.d.ts +409 -711
- package/dist/types/createReducer.d.ts +3 -11
- package/dist/types/createSelectors.d.ts +18 -80
- package/dist/types/index.d.ts +3 -5
- package/dist/types/mutate.d.ts +4 -94
- package/dist/types/query.d.ts +4 -123
- package/dist/types/types.d.ts +185 -346
- package/dist/types/useMutation.d.ts +4 -39
- package/dist/types/useQuery.d.ts +4 -40
- package/dist/types/utilsAndConstants.d.ts +23 -53
- package/package.json +16 -14
|
@@ -1,64 +1,55 @@
|
|
|
1
|
-
import {EMPTY_OBJECT} from './utilsAndConstants'
|
|
2
|
-
|
|
1
|
+
import { EMPTY_OBJECT } from './utilsAndConstants';
|
|
3
2
|
export const createSelectors = (cache) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
selectEntities: (state) => {
|
|
58
|
-
return cache.cacheStateSelector(state).entities
|
|
59
|
-
},
|
|
60
|
-
selectEntitiesByTypename: (state, typename) => {
|
|
61
|
-
return cache.cacheStateSelector(state).entities[typename]
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
}
|
|
3
|
+
const selectEntityById = (state, id, typename) => {
|
|
4
|
+
var _a;
|
|
5
|
+
return id == null ? undefined : (_a = cache.cacheStateSelector(state).entities[typename]) === null || _a === void 0 ? void 0 : _a[id];
|
|
6
|
+
};
|
|
7
|
+
const selectQueryState = (state, query, cacheKey) => {
|
|
8
|
+
var _a;
|
|
9
|
+
return (_a = cache.cacheStateSelector(state).queries[query][cacheKey]) !== null && _a !== void 0 ? _a : EMPTY_OBJECT;
|
|
10
|
+
};
|
|
11
|
+
const selectMutationState = (state, mutation) => {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = cache.cacheStateSelector(state).mutations[mutation]) !== null && _a !== void 0 ? _a : EMPTY_OBJECT;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
selectEntityById,
|
|
17
|
+
selectQueryState,
|
|
18
|
+
selectQueryResult: (state, query, cacheKey) => {
|
|
19
|
+
return selectQueryState(state, query, cacheKey).result;
|
|
20
|
+
},
|
|
21
|
+
selectQueryLoading: (state, query, cacheKey) => {
|
|
22
|
+
var _a;
|
|
23
|
+
return (_a = selectQueryState(state, query, cacheKey).loading) !== null && _a !== void 0 ? _a : false;
|
|
24
|
+
},
|
|
25
|
+
selectQueryError: (state, query, cacheKey) => {
|
|
26
|
+
return selectQueryState(state, query, cacheKey).error;
|
|
27
|
+
},
|
|
28
|
+
selectQueryParams: (state, query, cacheKey) => {
|
|
29
|
+
return selectQueryState(state, query, cacheKey).params;
|
|
30
|
+
},
|
|
31
|
+
selectQueryExpiresAt: (state, query, cacheKey) => {
|
|
32
|
+
return selectQueryState(state, query, cacheKey).expiresAt;
|
|
33
|
+
},
|
|
34
|
+
selectMutationState,
|
|
35
|
+
selectMutationResult: (state, mutation) => {
|
|
36
|
+
return selectMutationState(state, mutation).result;
|
|
37
|
+
},
|
|
38
|
+
selectMutationLoading: (state, mutation) => {
|
|
39
|
+
var _a;
|
|
40
|
+
return (_a = selectMutationState(state, mutation).loading) !== null && _a !== void 0 ? _a : false;
|
|
41
|
+
},
|
|
42
|
+
selectMutationError: (state, mutation) => {
|
|
43
|
+
return selectMutationState(state, mutation).error;
|
|
44
|
+
},
|
|
45
|
+
selectMutationParams: (state, mutation) => {
|
|
46
|
+
return selectMutationState(state, mutation).params;
|
|
47
|
+
},
|
|
48
|
+
selectEntities: (state) => {
|
|
49
|
+
return cache.cacheStateSelector(state).entities;
|
|
50
|
+
},
|
|
51
|
+
selectEntitiesByTypename: (state, typename) => {
|
|
52
|
+
return cache.cacheStateSelector(state).entities[typename];
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export {createCache, withTypenames} from './createCache'
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export {createStateComparer, defaultGetCacheKey, FetchPolicy, isEmptyObject, noop} from './utilsAndConstants'
|
|
1
|
+
export { createCache, withTypenames } from './createCache';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export { createStateComparer, defaultGetCacheKey, FetchPolicy, isEmptyObject, noop } from './utilsAndConstants';
|
package/dist/esm/mutate.js
CHANGED
|
@@ -1,150 +1,73 @@
|
|
|
1
|
-
var __awaiter =
|
|
2
|
-
|
|
3
|
-
function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) {
|
|
5
|
-
return value instanceof P
|
|
6
|
-
? value
|
|
7
|
-
: new P(function (resolve) {
|
|
8
|
-
resolve(value)
|
|
9
|
-
})
|
|
10
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next())
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
import {logDebug} from './utilsAndConstants'
|
|
33
|
-
|
|
34
|
-
export const mutate = (
|
|
35
|
-
logTag_1,
|
|
36
|
-
store_1,
|
|
37
|
-
cache_1,
|
|
38
|
-
actions_1,
|
|
39
|
-
selectors_1,
|
|
40
|
-
mutationKey_1,
|
|
41
|
-
params_1,
|
|
42
|
-
abortControllers_1,
|
|
43
|
-
...args_1
|
|
44
|
-
) =>
|
|
45
|
-
__awaiter(
|
|
46
|
-
void 0,
|
|
47
|
-
[
|
|
48
|
-
logTag_1,
|
|
49
|
-
store_1,
|
|
50
|
-
cache_1,
|
|
51
|
-
actions_1,
|
|
52
|
-
selectors_1,
|
|
53
|
-
mutationKey_1,
|
|
54
|
-
params_1,
|
|
55
|
-
abortControllers_1,
|
|
56
|
-
...args_1,
|
|
57
|
-
],
|
|
58
|
-
void 0,
|
|
59
|
-
function* (
|
|
60
|
-
logTag,
|
|
61
|
-
store,
|
|
62
|
-
cache,
|
|
63
|
-
actions,
|
|
64
|
-
selectors,
|
|
65
|
-
mutationKey,
|
|
66
|
-
params,
|
|
67
|
-
abortControllers,
|
|
68
|
-
onCompleted = cache.mutations[mutationKey].onCompleted,
|
|
69
|
-
onSuccess = cache.mutations[mutationKey].onSuccess,
|
|
70
|
-
onError = cache.mutations[mutationKey].onError
|
|
71
|
-
) {
|
|
72
|
-
var _a, _b
|
|
73
|
-
const {updateMutationStateAndEntities} = actions
|
|
74
|
-
let abortControllersOfStore = abortControllers.get(store)
|
|
75
|
-
if (abortControllersOfStore === undefined) {
|
|
76
|
-
abortControllersOfStore = {}
|
|
77
|
-
abortControllers.set(store, abortControllersOfStore)
|
|
78
|
-
}
|
|
79
|
-
{
|
|
80
|
-
const abortController = abortControllersOfStore[mutationKey]
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { logDebug } from './utilsAndConstants';
|
|
11
|
+
export const mutate = (logTag_1, store_1, cache_1, actions_1, selectors_1, mutationKey_1, params_1, abortControllers_1, ...args_1) => __awaiter(void 0, [logTag_1, store_1, cache_1, actions_1, selectors_1, mutationKey_1, params_1, abortControllers_1, ...args_1], void 0, function* (logTag, store, cache, actions, selectors, mutationKey, params, abortControllers, onCompleted = cache.mutations[mutationKey].onCompleted, onSuccess = cache.mutations[mutationKey].onSuccess, onError = cache.mutations[mutationKey].onError) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { updateMutationStateAndEntities } = actions;
|
|
14
|
+
let abortControllersOfStore = abortControllers.get(store);
|
|
15
|
+
if (abortControllersOfStore === undefined) {
|
|
16
|
+
abortControllersOfStore = {};
|
|
17
|
+
abortControllers.set(store, abortControllersOfStore);
|
|
18
|
+
}
|
|
19
|
+
{
|
|
20
|
+
const abortController = abortControllersOfStore[mutationKey];
|
|
81
21
|
cache.options.logsEnabled &&
|
|
82
|
-
|
|
22
|
+
logDebug(logTag, { mutationKey, params, previousAborted: abortController !== undefined });
|
|
83
23
|
if (abortController !== undefined) {
|
|
84
|
-
|
|
24
|
+
abortController.abort();
|
|
85
25
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
updateMutationStateAndEntities(mutationKey, {
|
|
113
|
-
error,
|
|
26
|
+
}
|
|
27
|
+
const abortController = new AbortController();
|
|
28
|
+
abortControllersOfStore[mutationKey] = abortController;
|
|
29
|
+
const mutatePromise = cache.mutations[mutationKey].mutation(params, store, abortController.signal);
|
|
30
|
+
store.dispatch(updateMutationStateAndEntities(mutationKey, {
|
|
31
|
+
loading: mutatePromise,
|
|
32
|
+
params,
|
|
33
|
+
result: undefined,
|
|
34
|
+
}));
|
|
35
|
+
let response;
|
|
36
|
+
let error;
|
|
37
|
+
try {
|
|
38
|
+
response = yield mutatePromise;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
error = e;
|
|
42
|
+
}
|
|
43
|
+
cache.options.logsEnabled &&
|
|
44
|
+
logDebug(`${logTag} finished`, { response, error, aborted: abortController.signal.aborted });
|
|
45
|
+
if (abortController.signal.aborted) {
|
|
46
|
+
return ABORTED_RESULT;
|
|
47
|
+
}
|
|
48
|
+
delete abortControllersOfStore[mutationKey];
|
|
49
|
+
if (error) {
|
|
50
|
+
store.dispatch(updateMutationStateAndEntities(mutationKey, {
|
|
51
|
+
error: error,
|
|
114
52
|
loading: undefined,
|
|
115
|
-
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
!(onError === null || onError === void 0
|
|
119
|
-
? void 0
|
|
120
|
-
: onError(error, params, store, actions, selectors))
|
|
121
|
-
) {
|
|
122
|
-
;(_b = (_a = cache.globals).onError) === null || _b === void 0
|
|
123
|
-
? void 0
|
|
124
|
-
: _b.call(_a, error, mutationKey, params, store, actions, selectors)
|
|
53
|
+
}));
|
|
54
|
+
if (!(onError === null || onError === void 0 ? void 0 : onError(error, params, store, actions, selectors))) {
|
|
55
|
+
(_b = (_a = cache.globals).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error, mutationKey, params, store, actions, selectors);
|
|
125
56
|
}
|
|
126
|
-
onCompleted === null || onCompleted === void 0
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
if (response) {
|
|
57
|
+
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response, error, params, store, actions, selectors);
|
|
58
|
+
return { error };
|
|
59
|
+
}
|
|
60
|
+
if (response) {
|
|
132
61
|
const newState = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
store.dispatch(updateMutationStateAndEntities(mutationKey, newState, response))
|
|
138
|
-
onSuccess === null || onSuccess === void 0
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
onCompleted === null || onCompleted === void 0
|
|
142
|
-
? void 0
|
|
143
|
-
: onCompleted(response, error, params, store, actions, selectors)
|
|
144
|
-
return {result: response.result}
|
|
145
|
-
}
|
|
146
|
-
throw new Error(`${logTag}: both error and response are not defined`)
|
|
62
|
+
error: undefined,
|
|
63
|
+
loading: undefined,
|
|
64
|
+
result: response.result,
|
|
65
|
+
};
|
|
66
|
+
store.dispatch(updateMutationStateAndEntities(mutationKey, newState, response));
|
|
67
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, params, store, actions, selectors);
|
|
68
|
+
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response, error, params, store, actions, selectors);
|
|
69
|
+
return { result: response.result };
|
|
147
70
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const ABORTED_RESULT = Object.freeze({aborted: true})
|
|
71
|
+
throw new Error(`${logTag}: both error and response are not defined`);
|
|
72
|
+
});
|
|
73
|
+
const ABORTED_RESULT = Object.freeze({ aborted: true });
|
package/dist/esm/query.js
CHANGED
|
@@ -1,160 +1,77 @@
|
|
|
1
|
-
var __awaiter =
|
|
2
|
-
|
|
3
|
-
function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) {
|
|
5
|
-
return value instanceof P
|
|
6
|
-
? value
|
|
7
|
-
: new P(function (resolve) {
|
|
8
|
-
resolve(value)
|
|
9
|
-
})
|
|
10
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next())
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
import {logDebug, noop} from './utilsAndConstants'
|
|
33
|
-
|
|
34
|
-
export const query = (
|
|
35
|
-
logTag,
|
|
36
|
-
store,
|
|
37
|
-
cache,
|
|
38
|
-
actions,
|
|
39
|
-
selectors,
|
|
40
|
-
queryKey,
|
|
41
|
-
cacheKey,
|
|
42
|
-
params,
|
|
43
|
-
secondsToLive,
|
|
44
|
-
onlyIfExpired,
|
|
45
|
-
skipFetch,
|
|
46
|
-
mergeResults,
|
|
47
|
-
onCompleted,
|
|
48
|
-
onSuccess,
|
|
49
|
-
onError
|
|
50
|
-
) =>
|
|
51
|
-
__awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
-
var _a, _b, _c, _d
|
|
53
|
-
if (secondsToLive === void 0) {
|
|
54
|
-
secondsToLive =
|
|
55
|
-
(_a = cache.queries[queryKey].secondsToLive) !== null && _a !== void 0
|
|
56
|
-
? _a
|
|
57
|
-
: cache.globals.queries.secondsToLive
|
|
58
|
-
}
|
|
59
|
-
if (mergeResults === void 0) {
|
|
60
|
-
mergeResults = cache.queries[queryKey].mergeResults
|
|
61
|
-
}
|
|
62
|
-
if (onCompleted === void 0) {
|
|
63
|
-
onCompleted = cache.queries[queryKey].onCompleted
|
|
64
|
-
}
|
|
65
|
-
if (onSuccess === void 0) {
|
|
66
|
-
onSuccess = cache.queries[queryKey].onSuccess
|
|
67
|
-
}
|
|
68
|
-
if (onError === void 0) {
|
|
69
|
-
onError = cache.queries[queryKey].onError
|
|
70
|
-
}
|
|
71
|
-
const {selectQueryResult, selectQueryState} = selectors
|
|
72
|
-
const logsEnabled = cache.options.logsEnabled
|
|
73
|
-
const queryStateOnStart = selectQueryState(store.getState(), queryKey, cacheKey)
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { logDebug, noop } from './utilsAndConstants';
|
|
11
|
+
export const query = (logTag, store, cache, actions, selectors, queryKey, cacheKey, params, secondsToLive, onlyIfExpired, skipFetch, mergeResults, onCompleted, onSuccess, onError) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
var _a, _b, _c, _d;
|
|
13
|
+
if (secondsToLive === void 0) { secondsToLive = (_a = cache.queries[queryKey].secondsToLive) !== null && _a !== void 0 ? _a : cache.globals.queries.secondsToLive; }
|
|
14
|
+
if (mergeResults === void 0) { mergeResults = cache.queries[queryKey].mergeResults; }
|
|
15
|
+
if (onCompleted === void 0) { onCompleted = cache.queries[queryKey].onCompleted; }
|
|
16
|
+
if (onSuccess === void 0) { onSuccess = cache.queries[queryKey].onSuccess; }
|
|
17
|
+
if (onError === void 0) { onError = cache.queries[queryKey].onError; }
|
|
18
|
+
const { selectQueryResult, selectQueryState } = selectors;
|
|
19
|
+
const logsEnabled = cache.options.logsEnabled;
|
|
20
|
+
const queryStateOnStart = selectQueryState(store.getState(), queryKey, cacheKey);
|
|
74
21
|
if (skipFetch) {
|
|
75
|
-
|
|
22
|
+
return { result: queryStateOnStart.result };
|
|
76
23
|
}
|
|
77
24
|
if (queryStateOnStart === null || queryStateOnStart === void 0 ? void 0 : queryStateOnStart.loading) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
25
|
+
logsEnabled &&
|
|
26
|
+
logDebug(`${logTag} fetch cancelled: already loading`, { queryStateOnStart, params, cacheKey });
|
|
27
|
+
const error = yield queryStateOnStart.loading.then(noop).catch(catchAndReturn);
|
|
28
|
+
const result = selectQueryResult(store.getState(), queryKey, cacheKey);
|
|
29
|
+
const cancelled = 'loading';
|
|
30
|
+
return error ? { cancelled, result, error } : { cancelled, result };
|
|
84
31
|
}
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
params,
|
|
95
|
-
cacheKey,
|
|
96
|
-
onlyIfExpired,
|
|
97
|
-
})
|
|
98
|
-
return {cancelled: 'not-expired', result: queryStateOnStart.result}
|
|
32
|
+
if (onlyIfExpired && (queryStateOnStart === null || queryStateOnStart === void 0 ? void 0 : queryStateOnStart.expiresAt) != null && queryStateOnStart.expiresAt > Date.now()) {
|
|
33
|
+
logsEnabled &&
|
|
34
|
+
logDebug(`${logTag} fetch cancelled: not expired yet`, {
|
|
35
|
+
queryStateOnStart,
|
|
36
|
+
params,
|
|
37
|
+
cacheKey,
|
|
38
|
+
onlyIfExpired,
|
|
39
|
+
});
|
|
40
|
+
return { cancelled: 'not-expired', result: queryStateOnStart.result };
|
|
99
41
|
}
|
|
100
|
-
const {updateQueryStateAndEntities} = actions
|
|
101
|
-
const fetchPromise = cache.queries[queryKey].query(params, store)
|
|
102
|
-
store.dispatch(
|
|
103
|
-
updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
42
|
+
const { updateQueryStateAndEntities } = actions;
|
|
43
|
+
const fetchPromise = cache.queries[queryKey].query(params, store);
|
|
44
|
+
store.dispatch(updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
104
45
|
loading: fetchPromise,
|
|
105
46
|
params,
|
|
106
|
-
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
logDebug(`${logTag} started`, {queryKey, params, cacheKey, queryStateOnStart, onlyIfExpired})
|
|
110
|
-
let response
|
|
47
|
+
}));
|
|
48
|
+
logsEnabled && logDebug(`${logTag} started`, { queryKey, params, cacheKey, queryStateOnStart, onlyIfExpired });
|
|
49
|
+
let response;
|
|
111
50
|
try {
|
|
112
|
-
|
|
113
|
-
} catch (error) {
|
|
114
|
-
store.dispatch(
|
|
115
|
-
updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
116
|
-
error,
|
|
117
|
-
loading: undefined,
|
|
118
|
-
})
|
|
119
|
-
)
|
|
120
|
-
if (!(onError === null || onError === void 0 ? void 0 : onError(error, params, store))) {
|
|
121
|
-
;(_c = (_b = cache.globals).onError) === null || _c === void 0
|
|
122
|
-
? void 0
|
|
123
|
-
: _c.call(_b, error, queryKey, params, store, actions, selectors)
|
|
124
|
-
}
|
|
125
|
-
onCompleted === null || onCompleted === void 0
|
|
126
|
-
? void 0
|
|
127
|
-
: onCompleted(undefined, error, params, store, actions, selectors)
|
|
128
|
-
return {error, result: selectQueryResult(store.getState(), queryKey, cacheKey)}
|
|
51
|
+
response = yield fetchPromise;
|
|
129
52
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
? mergeResults(
|
|
141
|
-
selectQueryResult(store.getState(), queryKey, cacheKey),
|
|
142
|
-
response,
|
|
143
|
-
params,
|
|
144
|
-
store,
|
|
145
|
-
actions,
|
|
146
|
-
selectors
|
|
147
|
-
)
|
|
148
|
-
: response.result,
|
|
53
|
+
catch (error) {
|
|
54
|
+
store.dispatch(updateQueryStateAndEntities(queryKey, cacheKey, {
|
|
55
|
+
error: error,
|
|
56
|
+
loading: undefined,
|
|
57
|
+
}));
|
|
58
|
+
if (!(onError === null || onError === void 0 ? void 0 : onError(error, params, store))) {
|
|
59
|
+
(_c = (_b = cache.globals).onError) === null || _c === void 0 ? void 0 : _c.call(_b, error, queryKey, params, store, actions, selectors);
|
|
60
|
+
}
|
|
61
|
+
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(undefined, error, params, store, actions, selectors);
|
|
62
|
+
return { error, result: selectQueryResult(store.getState(), queryKey, cacheKey) };
|
|
149
63
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
64
|
+
const newState = {
|
|
65
|
+
error: undefined,
|
|
66
|
+
loading: undefined,
|
|
67
|
+
expiresAt: (_d = response.expiresAt) !== null && _d !== void 0 ? _d : (secondsToLive != null ? Date.now() + secondsToLive * 1000 : undefined),
|
|
68
|
+
result: mergeResults
|
|
69
|
+
? mergeResults(selectQueryResult(store.getState(), queryKey, cacheKey), response, params, store, actions, selectors)
|
|
70
|
+
: response.result,
|
|
71
|
+
};
|
|
72
|
+
store.dispatch(updateQueryStateAndEntities(queryKey, cacheKey, newState, response));
|
|
73
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, params, store, actions, selectors);
|
|
74
|
+
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response, undefined, params, store, actions, selectors);
|
|
75
|
+
return { result: newState === null || newState === void 0 ? void 0 : newState.result };
|
|
76
|
+
});
|
|
77
|
+
const catchAndReturn = (x) => x;
|
package/dist/esm/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {};
|