@data-client/core 0.13.1 → 0.14.0
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/dist/index.js +198 -214
- package/dist/index.umd.min.js +1 -1
- package/legacy/actions.js +1 -1
- package/legacy/controller/Controller.js +21 -30
- package/legacy/controller/actions/createExpireAll.js +8 -0
- package/legacy/controller/actions/createFetch.js +27 -0
- package/legacy/controller/actions/createInvalidate.js +10 -0
- package/legacy/controller/actions/createInvalidateAll.js +8 -0
- package/legacy/controller/actions/createMeta.js +9 -0
- package/legacy/controller/actions/createOptimistic.js +17 -0
- package/legacy/controller/actions/createReset.js +8 -0
- package/legacy/controller/actions/createSet.js +17 -0
- package/legacy/controller/actions/createSetResponse.js +26 -0
- package/legacy/controller/actions/createSubscription.js +22 -0
- package/legacy/controller/actions/index.js +11 -0
- package/legacy/index.js +3 -4
- package/legacy/internal.js +1 -2
- package/legacy/manager/LogoutManager.js +2 -2
- package/legacy/manager/NetworkManager.js +39 -35
- package/legacy/manager/PollingSubscription.js +3 -3
- package/legacy/manager/SubscriptionManager.js +3 -3
- package/legacy/state/reducer/createReducer.js +2 -2
- package/legacy/state/reducer/fetchReducer.js +6 -10
- package/legacy/state/reducer/invalidateReducer.js +2 -2
- package/legacy/state/reducer/setReducer.js +11 -3
- package/legacy/state/reducer/setResponseReducer.js +17 -17
- package/legacy/types.js +1 -1
- package/lib/actions.d.ts +35 -41
- package/lib/actions.d.ts.map +1 -1
- package/lib/actions.js +1 -1
- package/lib/controller/Controller.d.ts +18 -17
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +21 -30
- package/lib/controller/actions/createExpireAll.d.ts +3 -0
- package/lib/controller/actions/createExpireAll.d.ts.map +1 -0
- package/lib/controller/actions/createExpireAll.js +8 -0
- package/lib/controller/{createFetch.d.ts → actions/createFetch.d.ts} +3 -3
- package/lib/controller/actions/createFetch.d.ts.map +1 -0
- package/lib/controller/actions/createFetch.js +27 -0
- package/lib/controller/actions/createInvalidate.d.ts +6 -0
- package/lib/controller/actions/createInvalidate.d.ts.map +1 -0
- package/lib/controller/actions/createInvalidate.js +10 -0
- package/lib/controller/actions/createInvalidateAll.d.ts +3 -0
- package/lib/controller/actions/createInvalidateAll.d.ts.map +1 -0
- package/lib/controller/actions/createInvalidateAll.js +8 -0
- package/lib/controller/actions/createMeta.d.ts +3 -0
- package/lib/controller/actions/createMeta.d.ts.map +1 -0
- package/lib/controller/actions/createMeta.js +9 -0
- package/lib/controller/actions/createOptimistic.d.ts +7 -0
- package/lib/controller/actions/createOptimistic.d.ts.map +1 -0
- package/lib/controller/actions/createOptimistic.js +17 -0
- package/lib/controller/actions/createReset.d.ts +3 -0
- package/lib/controller/actions/createReset.d.ts.map +1 -0
- package/lib/controller/actions/createReset.js +8 -0
- package/lib/controller/actions/createSet.d.ts +8 -0
- package/lib/controller/actions/createSet.d.ts.map +1 -0
- package/lib/controller/actions/createSet.js +17 -0
- package/lib/controller/{createSetResponse.d.ts → actions/createSetResponse.d.ts} +4 -4
- package/lib/controller/actions/createSetResponse.d.ts.map +1 -0
- package/lib/controller/actions/createSetResponse.js +26 -0
- package/lib/controller/{createSubscription.d.ts → actions/createSubscription.d.ts} +1 -1
- package/lib/controller/actions/createSubscription.d.ts.map +1 -0
- package/lib/controller/actions/createSubscription.js +22 -0
- package/lib/controller/actions/index.d.ts +11 -0
- package/lib/controller/actions/index.d.ts.map +1 -0
- package/lib/controller/actions/index.js +11 -0
- package/lib/index.d.ts +1 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -4
- package/lib/internal.d.ts +0 -1
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +1 -2
- package/lib/manager/LogoutManager.js +2 -2
- package/lib/manager/NetworkManager.d.ts +7 -2
- package/lib/manager/NetworkManager.d.ts.map +1 -1
- package/lib/manager/NetworkManager.js +39 -35
- package/lib/manager/PollingSubscription.js +3 -3
- package/lib/manager/SubscriptionManager.js +3 -3
- package/lib/state/reducer/createReducer.js +2 -2
- package/lib/state/reducer/expireReducer.d.ts +6 -8
- package/lib/state/reducer/expireReducer.d.ts.map +1 -1
- package/lib/state/reducer/fetchReducer.d.ts.map +1 -1
- package/lib/state/reducer/fetchReducer.js +8 -12
- package/lib/state/reducer/invalidateReducer.d.ts +5 -7
- package/lib/state/reducer/invalidateReducer.d.ts.map +1 -1
- package/lib/state/reducer/invalidateReducer.js +2 -2
- package/lib/state/reducer/setReducer.d.ts +2 -1
- package/lib/state/reducer/setReducer.d.ts.map +1 -1
- package/lib/state/reducer/setReducer.js +11 -3
- package/lib/state/reducer/setResponseReducer.d.ts.map +1 -1
- package/lib/state/reducer/setResponseReducer.js +17 -17
- package/lib/types.d.ts +3 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -1
- package/package.json +2 -2
- package/src/actions.ts +37 -43
- package/src/controller/Controller.ts +29 -26
- package/src/controller/__tests__/Controller.ts +2 -2
- package/src/controller/actions/createExpireAll.ts +11 -0
- package/src/controller/{createFetch.ts → actions/createFetch.ts} +9 -13
- package/src/controller/actions/createInvalidate.ts +14 -0
- package/src/controller/actions/createInvalidateAll.ts +11 -0
- package/src/controller/actions/createMeta.ts +13 -0
- package/src/controller/actions/createOptimistic.ts +32 -0
- package/src/controller/actions/createReset.ts +9 -0
- package/src/controller/actions/createSet.ts +31 -0
- package/src/controller/{createSetResponse.ts → actions/createSetResponse.ts} +17 -23
- package/src/controller/{createSubscription.ts → actions/createSubscription.ts} +6 -10
- package/src/controller/actions/index.ts +13 -0
- package/src/index.ts +1 -3
- package/src/internal.ts +0 -1
- package/src/manager/LogoutManager.ts +1 -1
- package/src/manager/NetworkManager.ts +41 -32
- package/src/manager/PollingSubscription.ts +2 -2
- package/src/manager/SubscriptionManager.ts +2 -2
- package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +4 -10
- package/src/manager/__tests__/logoutManager.ts +1 -1
- package/src/manager/__tests__/networkManager.ts +37 -25
- package/src/manager/__tests__/pollingSubscription.ts +3 -3
- package/src/manager/__tests__/subscriptionManager.ts +22 -27
- package/src/state/__tests__/reducer.ts +110 -44
- package/src/state/reducer/createReducer.ts +1 -1
- package/src/state/reducer/fetchReducer.ts +12 -18
- package/src/state/reducer/invalidateReducer.ts +1 -1
- package/src/state/reducer/setReducer.ts +17 -6
- package/src/state/reducer/setResponseReducer.ts +18 -20
- package/src/types.ts +4 -4
- package/ts3.4/actions.d.ts +36 -42
- package/ts3.4/controller/Controller.d.ts +23 -19
- package/ts3.4/controller/actions/createExpireAll.d.ts +3 -0
- package/ts3.4/controller/{createFetch.d.ts → actions/createFetch.d.ts} +3 -3
- package/ts3.4/controller/{createInvalidate.d.ts → actions/createInvalidate.d.ts} +2 -2
- package/ts3.4/controller/actions/createInvalidateAll.d.ts +3 -0
- package/ts3.4/controller/actions/createMeta.d.ts +3 -0
- package/ts3.4/controller/actions/createOptimistic.d.ts +9 -0
- package/ts3.4/controller/actions/createReset.d.ts +3 -0
- package/ts3.4/controller/actions/createSet.d.ts +10 -0
- package/ts3.4/controller/{createSetResponse.d.ts → actions/createSetResponse.d.ts} +4 -4
- package/ts3.4/controller/{createSubscription.d.ts → actions/createSubscription.d.ts} +1 -1
- package/ts3.4/controller/actions/index.d.ts +11 -0
- package/ts3.4/index.d.ts +2 -3
- package/ts3.4/internal.d.ts +0 -1
- package/ts3.4/manager/NetworkManager.d.ts +7 -2
- package/ts3.4/state/reducer/expireReducer.d.ts +6 -8
- package/ts3.4/state/reducer/invalidateReducer.d.ts +5 -7
- package/ts3.4/state/reducer/setReducer.d.ts +2 -1
- package/ts3.4/types.d.ts +3 -3
- package/legacy/controller/createExpireAll.js +0 -8
- package/legacy/controller/createFetch.js +0 -31
- package/legacy/controller/createInvalidate.js +0 -12
- package/legacy/controller/createInvalidateAll.js +0 -8
- package/legacy/controller/createOptimistic.js +0 -27
- package/legacy/controller/createReset.js +0 -8
- package/legacy/controller/createSet.js +0 -28
- package/legacy/controller/createSetResponse.js +0 -32
- package/legacy/controller/createSubscription.js +0 -26
- package/legacy/state/RIC.js +0 -3
- package/lib/controller/createExpireAll.d.ts +0 -3
- package/lib/controller/createExpireAll.d.ts.map +0 -1
- package/lib/controller/createExpireAll.js +0 -8
- package/lib/controller/createFetch.d.ts.map +0 -1
- package/lib/controller/createFetch.js +0 -31
- package/lib/controller/createInvalidate.d.ts +0 -6
- package/lib/controller/createInvalidate.d.ts.map +0 -1
- package/lib/controller/createInvalidate.js +0 -12
- package/lib/controller/createInvalidateAll.d.ts +0 -3
- package/lib/controller/createInvalidateAll.d.ts.map +0 -1
- package/lib/controller/createInvalidateAll.js +0 -8
- package/lib/controller/createOptimistic.d.ts +0 -10
- package/lib/controller/createOptimistic.d.ts.map +0 -1
- package/lib/controller/createOptimistic.js +0 -27
- package/lib/controller/createReset.d.ts +0 -3
- package/lib/controller/createReset.d.ts.map +0 -1
- package/lib/controller/createReset.js +0 -8
- package/lib/controller/createSet.d.ts +0 -8
- package/lib/controller/createSet.d.ts.map +0 -1
- package/lib/controller/createSet.js +0 -28
- package/lib/controller/createSetResponse.d.ts.map +0 -1
- package/lib/controller/createSetResponse.js +0 -32
- package/lib/controller/createSubscription.d.ts.map +0 -1
- package/lib/controller/createSubscription.js +0 -26
- package/lib/state/RIC.d.ts +0 -3
- package/lib/state/RIC.d.ts.map +0 -1
- package/lib/state/RIC.js +0 -3
- package/src/controller/createExpireAll.ts +0 -11
- package/src/controller/createInvalidate.ts +0 -16
- package/src/controller/createInvalidateAll.ts +0 -11
- package/src/controller/createOptimistic.ts +0 -41
- package/src/controller/createReset.ts +0 -9
- package/src/controller/createSet.ts +0 -39
- package/src/state/RIC.ts +0 -5
- package/src/state/__tests__/RIC.web.ts +0 -16
- package/ts3.4/controller/createExpireAll.d.ts +0 -3
- package/ts3.4/controller/createInvalidateAll.d.ts +0 -3
- package/ts3.4/controller/createOptimistic.d.ts +0 -12
- package/ts3.4/controller/createReset.d.ts +0 -3
- package/ts3.4/controller/createSet.d.ts +0 -10
- package/ts3.4/state/RIC.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -4,9 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var normalizr = require('@data-client/normalizr');
|
|
6
6
|
|
|
7
|
-
const RIC = typeof requestIdleCallback === 'function' ? requestIdleCallback : cb => cb();
|
|
8
|
-
var RIC$1 = RIC;
|
|
9
|
-
|
|
10
7
|
function expireReducer(state, action) {
|
|
11
8
|
const meta = {
|
|
12
9
|
...state.meta
|
|
@@ -26,6 +23,15 @@ function expireReducer(state, action) {
|
|
|
26
23
|
};
|
|
27
24
|
}
|
|
28
25
|
|
|
26
|
+
function createMeta(expiryLength, fetchedAt) {
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
return {
|
|
29
|
+
fetchedAt: fetchedAt != null ? fetchedAt : now,
|
|
30
|
+
date: now,
|
|
31
|
+
expiresAt: now + expiryLength
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
const FETCH_TYPE = 'rdc/fetch';
|
|
30
36
|
const SET_TYPE = 'rdc/set';
|
|
31
37
|
const SET_RESPONSE_TYPE = 'rdc/setresponse';
|
|
@@ -53,52 +59,37 @@ var actionTypes = /*#__PURE__*/Object.freeze({
|
|
|
53
59
|
GC_TYPE: GC_TYPE
|
|
54
60
|
});
|
|
55
61
|
|
|
56
|
-
function createOptimistic(endpoint, {
|
|
57
|
-
|
|
58
|
-
fetchedAt
|
|
59
|
-
}) {
|
|
60
|
-
var _endpoint$dataExpiryL;
|
|
61
|
-
const expiryLength = (_endpoint$dataExpiryL = endpoint.dataExpiryLength) != null ? _endpoint$dataExpiryL : 60000;
|
|
62
|
+
function createOptimistic(endpoint, args, fetchedAt) {
|
|
63
|
+
var _endpoint$dataExpiryL, _endpoint$dataExpiryL2;
|
|
62
64
|
/* istanbul ignore next */
|
|
63
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
65
|
+
if (process.env.NODE_ENV === 'development' && ((_endpoint$dataExpiryL = endpoint.dataExpiryLength) != null ? _endpoint$dataExpiryL : 0) < 0) {
|
|
64
66
|
throw new Error('Negative expiry length are not allowed.');
|
|
65
67
|
}
|
|
66
|
-
|
|
67
|
-
const meta = {
|
|
68
|
-
args,
|
|
69
|
-
fetchedAt,
|
|
70
|
-
date: now,
|
|
71
|
-
expiresAt: now + expiryLength,
|
|
72
|
-
key: endpoint.key(...args)
|
|
73
|
-
};
|
|
74
|
-
const action = {
|
|
68
|
+
return {
|
|
75
69
|
type: OPTIMISTIC_TYPE,
|
|
76
70
|
endpoint,
|
|
77
|
-
|
|
71
|
+
args,
|
|
72
|
+
key: endpoint.key(...args),
|
|
73
|
+
meta: createMeta((_endpoint$dataExpiryL2 = endpoint.dataExpiryLength) != null ? _endpoint$dataExpiryL2 : 60000, fetchedAt)
|
|
78
74
|
};
|
|
79
|
-
return action;
|
|
80
75
|
}
|
|
81
76
|
|
|
82
77
|
function fetchReducer(state, action) {
|
|
83
|
-
let setAction;
|
|
84
78
|
if (action.endpoint.getOptimisticResponse && action.endpoint.sideEffect) {
|
|
85
|
-
setAction = createOptimistic(action.endpoint,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
const setAction = createOptimistic(action.endpoint, action.args, action.meta.fetchedAt);
|
|
80
|
+
return {
|
|
81
|
+
...state,
|
|
82
|
+
optimistic: [...state.optimistic, setAction]
|
|
83
|
+
};
|
|
89
84
|
} else {
|
|
90
85
|
// If 'fetch' action reaches the reducer there are no middlewares installed to handle it
|
|
91
86
|
/* istanbul ignore next */
|
|
92
87
|
if (process.env.NODE_ENV !== 'production') {
|
|
93
88
|
console.warn('Fetch appears unhandled - you are likely missing the NetworkManager middleware');
|
|
94
|
-
console.warn('See https://dataclient.io/docs/guides/redux
|
|
89
|
+
console.warn('See https://dataclient.io/docs/guides/redux for hooking up redux');
|
|
95
90
|
}
|
|
96
91
|
return state;
|
|
97
92
|
}
|
|
98
|
-
return {
|
|
99
|
-
...state,
|
|
100
|
-
optimistic: [...state.optimistic, setAction]
|
|
101
|
-
};
|
|
102
93
|
}
|
|
103
94
|
|
|
104
95
|
function invalidateReducer(state, action) {
|
|
@@ -119,7 +110,7 @@ function invalidateReducer(state, action) {
|
|
|
119
110
|
meta[key] = itemMeta;
|
|
120
111
|
};
|
|
121
112
|
if (action.type === INVALIDATE_TYPE) {
|
|
122
|
-
invalidateKey(action.
|
|
113
|
+
invalidateKey(action.key);
|
|
123
114
|
} else {
|
|
124
115
|
Object.keys(endpoints).forEach(key => {
|
|
125
116
|
if (action.testKey(key)) {
|
|
@@ -134,13 +125,21 @@ function invalidateReducer(state, action) {
|
|
|
134
125
|
};
|
|
135
126
|
}
|
|
136
127
|
|
|
137
|
-
function setReducer(state, action) {
|
|
128
|
+
function setReducer(state, action, controller) {
|
|
129
|
+
let value;
|
|
130
|
+
if (typeof action.value === 'function') {
|
|
131
|
+
const previousValue = controller.get(action.schema, ...action.args, state);
|
|
132
|
+
if (previousValue === undefined) return state;
|
|
133
|
+
value = action.value(previousValue);
|
|
134
|
+
} else {
|
|
135
|
+
value = action.value;
|
|
136
|
+
}
|
|
138
137
|
try {
|
|
139
138
|
const {
|
|
140
139
|
entities,
|
|
141
140
|
indexes,
|
|
142
141
|
entityMeta
|
|
143
|
-
} = normalizr.normalize(action.
|
|
142
|
+
} = normalizr.normalize(action.schema, value, action.args, state, action.meta);
|
|
144
143
|
return {
|
|
145
144
|
entities,
|
|
146
145
|
indexes,
|
|
@@ -165,19 +164,19 @@ class AbortOptimistic extends Error {}
|
|
|
165
164
|
|
|
166
165
|
function setResponseReducer(state, action, controller) {
|
|
167
166
|
if (action.error) {
|
|
168
|
-
return reduceError(state, action, action.
|
|
167
|
+
return reduceError(state, action, action.response);
|
|
169
168
|
}
|
|
170
169
|
try {
|
|
171
|
-
var _state$meta$action$
|
|
172
|
-
let
|
|
173
|
-
// for true set's
|
|
170
|
+
var _state$meta$action$ke;
|
|
171
|
+
let response;
|
|
172
|
+
// for true set's response is contained in action
|
|
174
173
|
if (action.type === OPTIMISTIC_TYPE) {
|
|
175
174
|
// this should never happen
|
|
176
175
|
/* istanbul ignore if */
|
|
177
176
|
if (!action.endpoint.getOptimisticResponse) return state;
|
|
178
177
|
try {
|
|
179
178
|
// compute optimistic response based on current state
|
|
180
|
-
|
|
179
|
+
response = action.endpoint.getOptimisticResponse.call(action.endpoint, controller.snapshot(state, action.meta.fetchedAt), ...action.args);
|
|
181
180
|
} catch (e) {
|
|
182
181
|
// AbortOptimistic means 'do nothing', otherwise we count the exception as endpoint failure
|
|
183
182
|
if (e.constructor === AbortOptimistic) {
|
|
@@ -186,21 +185,21 @@ function setResponseReducer(state, action, controller) {
|
|
|
186
185
|
throw e;
|
|
187
186
|
}
|
|
188
187
|
} else {
|
|
189
|
-
|
|
188
|
+
response = action.response;
|
|
190
189
|
}
|
|
191
190
|
const {
|
|
192
191
|
result,
|
|
193
192
|
entities,
|
|
194
193
|
indexes,
|
|
195
194
|
entityMeta
|
|
196
|
-
} = normalizr.normalize(
|
|
195
|
+
} = normalizr.normalize(action.endpoint.schema, response, action.args, state, action.meta);
|
|
197
196
|
const endpoints = {
|
|
198
197
|
...state.endpoints,
|
|
199
|
-
[action.
|
|
198
|
+
[action.key]: result
|
|
200
199
|
};
|
|
201
200
|
try {
|
|
202
201
|
if (action.endpoint.update) {
|
|
203
|
-
const updaters = action.endpoint.update(result, ...action.
|
|
202
|
+
const updaters = action.endpoint.update(result, ...action.args);
|
|
204
203
|
Object.keys(updaters).forEach(key => {
|
|
205
204
|
endpoints[key] = updaters[key](endpoints[key]);
|
|
206
205
|
});
|
|
@@ -208,7 +207,7 @@ function setResponseReducer(state, action, controller) {
|
|
|
208
207
|
// no reason to completely fail because of user-code error
|
|
209
208
|
// integrity of this state update is still guaranteed
|
|
210
209
|
} catch (error) {
|
|
211
|
-
console.error(`The following error occured during Endpoint.update() for ${action.
|
|
210
|
+
console.error(`The following error occured during Endpoint.update() for ${action.key}`);
|
|
212
211
|
console.error(error);
|
|
213
212
|
}
|
|
214
213
|
return {
|
|
@@ -218,10 +217,10 @@ function setResponseReducer(state, action, controller) {
|
|
|
218
217
|
entityMeta,
|
|
219
218
|
meta: {
|
|
220
219
|
...state.meta,
|
|
221
|
-
[action.
|
|
220
|
+
[action.key]: {
|
|
222
221
|
date: action.meta.date,
|
|
223
222
|
expiresAt: action.meta.expiresAt,
|
|
224
|
-
prevExpiresAt: (_state$meta$action$
|
|
223
|
+
prevExpiresAt: (_state$meta$action$ke = state.meta[action.key]) == null ? void 0 : _state$meta$action$ke.expiresAt
|
|
225
224
|
}
|
|
226
225
|
},
|
|
227
226
|
optimistic: filterOptimistic(state, action),
|
|
@@ -230,8 +229,8 @@ function setResponseReducer(state, action, controller) {
|
|
|
230
229
|
// reducer must update the state, so in case of processing errors we simply compute the endpoints inline
|
|
231
230
|
} catch (error) {
|
|
232
231
|
if (typeof error === 'object') {
|
|
233
|
-
error.message = `Error processing ${action.
|
|
234
|
-
if ('
|
|
232
|
+
error.message = `Error processing ${action.key}\n\nFull Schema: ${JSON.stringify(action.endpoint.schema, undefined, 2)}\n\nError:\n${error.message}`;
|
|
233
|
+
if ('response' in action) error.response = action.response;
|
|
235
234
|
error.status = 400;
|
|
236
235
|
}
|
|
237
236
|
|
|
@@ -257,7 +256,7 @@ function reduceError(state, action, error) {
|
|
|
257
256
|
...state,
|
|
258
257
|
meta: {
|
|
259
258
|
...state.meta,
|
|
260
|
-
[action.
|
|
259
|
+
[action.key]: {
|
|
261
260
|
date: action.meta.date,
|
|
262
261
|
error,
|
|
263
262
|
expiresAt: action.meta.expiresAt,
|
|
@@ -269,7 +268,7 @@ function reduceError(state, action, error) {
|
|
|
269
268
|
}
|
|
270
269
|
/** Filter all requests with same serialization that did not start after the resolving request */
|
|
271
270
|
function filterOptimistic(state, resolvingAction) {
|
|
272
|
-
return state.optimistic.filter(optimisticAction => optimisticAction.
|
|
271
|
+
return state.optimistic.filter(optimisticAction => optimisticAction.key !== resolvingAction.key || (optimisticAction.type === OPTIMISTIC_TYPE ? optimisticAction.meta.fetchedAt !== resolvingAction.meta.fetchedAt : optimisticAction.meta.date > resolvingAction.meta.date));
|
|
273
272
|
}
|
|
274
273
|
|
|
275
274
|
function createReducer(controller) {
|
|
@@ -295,7 +294,7 @@ function createReducer(controller) {
|
|
|
295
294
|
case SET_RESPONSE_TYPE:
|
|
296
295
|
return setResponseReducer(state, action, controller);
|
|
297
296
|
case SET_TYPE:
|
|
298
|
-
return setReducer(state, action);
|
|
297
|
+
return setReducer(state, action, controller);
|
|
299
298
|
case INVALIDATEALL_TYPE:
|
|
300
299
|
case INVALIDATE_TYPE:
|
|
301
300
|
return invalidateReducer(state, action);
|
|
@@ -327,69 +326,27 @@ var internal = /*#__PURE__*/Object.freeze({
|
|
|
327
326
|
__proto__: null,
|
|
328
327
|
MemoCache: normalizr.MemoCache,
|
|
329
328
|
INVALID: normalizr.INVALID,
|
|
330
|
-
RIC: RIC$1,
|
|
331
329
|
initialState: initialState
|
|
332
330
|
});
|
|
333
331
|
|
|
334
|
-
function
|
|
335
|
-
return {
|
|
336
|
-
type: EXPIREALL_TYPE,
|
|
337
|
-
testKey
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Requesting a fetch to begin
|
|
343
|
-
*/
|
|
344
|
-
function createFetch(endpoint, {
|
|
332
|
+
function createSubscription(endpoint, {
|
|
345
333
|
args
|
|
346
334
|
}) {
|
|
347
|
-
const key = endpoint.key(...args);
|
|
348
|
-
let resolve = 0;
|
|
349
|
-
let reject = 0;
|
|
350
|
-
const promise = new Promise((a, b) => {
|
|
351
|
-
[resolve, reject] = [a, b];
|
|
352
|
-
});
|
|
353
|
-
const meta = {
|
|
354
|
-
args,
|
|
355
|
-
key,
|
|
356
|
-
throttle: !endpoint.sideEffect,
|
|
357
|
-
resolve,
|
|
358
|
-
reject,
|
|
359
|
-
promise,
|
|
360
|
-
createdAt: Date.now(),
|
|
361
|
-
nm: false
|
|
362
|
-
};
|
|
363
335
|
return {
|
|
364
|
-
type:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
endpoint
|
|
336
|
+
type: SUBSCRIBE_TYPE,
|
|
337
|
+
endpoint,
|
|
338
|
+
args,
|
|
339
|
+
key: endpoint.key(...args)
|
|
368
340
|
};
|
|
369
341
|
}
|
|
370
|
-
|
|
371
|
-
function createInvalidate(endpoint, {
|
|
342
|
+
function createUnsubscription(endpoint, {
|
|
372
343
|
args
|
|
373
344
|
}) {
|
|
374
345
|
return {
|
|
375
|
-
type:
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function createInvalidateAll(testKey) {
|
|
383
|
-
return {
|
|
384
|
-
type: INVALIDATEALL_TYPE,
|
|
385
|
-
testKey
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
function createReset() {
|
|
390
|
-
return {
|
|
391
|
-
type: RESET_TYPE,
|
|
392
|
-
date: Date.now()
|
|
346
|
+
type: UNSUBSCRIBE_TYPE,
|
|
347
|
+
endpoint,
|
|
348
|
+
args,
|
|
349
|
+
key: endpoint.key(...args)
|
|
393
350
|
};
|
|
394
351
|
}
|
|
395
352
|
|
|
@@ -399,87 +356,114 @@ const ensurePojo =
|
|
|
399
356
|
typeof FormData !== 'undefined' ? body => body instanceof FormData ? Object.fromEntries(body.entries()) : body : /* istanbul ignore next */body => body;
|
|
400
357
|
var ensurePojo$1 = ensurePojo;
|
|
401
358
|
|
|
402
|
-
function
|
|
359
|
+
function createSetResponse(endpoint, {
|
|
403
360
|
args,
|
|
404
361
|
fetchedAt,
|
|
405
|
-
|
|
362
|
+
response,
|
|
363
|
+
error = false
|
|
406
364
|
}) {
|
|
407
|
-
|
|
365
|
+
var _endpoint$errorExpiry, _endpoint$dataExpiryL;
|
|
366
|
+
const expiryLength = error ? (_endpoint$errorExpiry = endpoint.errorExpiryLength) != null ? _endpoint$errorExpiry : 1000 : (_endpoint$dataExpiryL = endpoint.dataExpiryLength) != null ? _endpoint$dataExpiryL : 60000;
|
|
408
367
|
/* istanbul ignore next */
|
|
409
368
|
if (process.env.NODE_ENV === 'development' && expiryLength < 0) {
|
|
410
369
|
throw new Error('Negative expiry length are not allowed.');
|
|
411
370
|
}
|
|
412
|
-
|
|
413
|
-
|
|
371
|
+
return {
|
|
372
|
+
type: SET_RESPONSE_TYPE,
|
|
373
|
+
endpoint,
|
|
374
|
+
response,
|
|
414
375
|
args: args.map(ensurePojo$1),
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
376
|
+
key: endpoint.key(...args),
|
|
377
|
+
meta: createMeta(expiryLength, fetchedAt),
|
|
378
|
+
error
|
|
418
379
|
};
|
|
419
|
-
const action = {
|
|
420
|
-
type: SET_TYPE,
|
|
421
|
-
value,
|
|
422
|
-
schema,
|
|
423
|
-
meta
|
|
424
|
-
};
|
|
425
|
-
return action;
|
|
426
380
|
}
|
|
427
381
|
|
|
428
|
-
function
|
|
382
|
+
function createSet(schema, {
|
|
429
383
|
args,
|
|
430
384
|
fetchedAt,
|
|
431
|
-
|
|
432
|
-
error = false
|
|
385
|
+
value
|
|
433
386
|
}) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
throw new Error('Negative expiry length are not allowed.');
|
|
439
|
-
}
|
|
440
|
-
const now = Date.now();
|
|
441
|
-
const meta = {
|
|
387
|
+
return {
|
|
388
|
+
type: SET_TYPE,
|
|
389
|
+
schema,
|
|
390
|
+
value,
|
|
442
391
|
args: args.map(ensurePojo$1),
|
|
443
|
-
|
|
444
|
-
date: now,
|
|
445
|
-
expiresAt: now + expiryLength,
|
|
446
|
-
key: endpoint.key(...args)
|
|
392
|
+
meta: createMeta(60000, fetchedAt)
|
|
447
393
|
};
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function createReset() {
|
|
397
|
+
return {
|
|
398
|
+
type: RESET_TYPE,
|
|
399
|
+
date: Date.now()
|
|
453
400
|
};
|
|
454
|
-
if (error) action.error = true;
|
|
455
|
-
return action;
|
|
456
401
|
}
|
|
457
402
|
|
|
458
|
-
function
|
|
403
|
+
function createInvalidateAll(testKey) {
|
|
404
|
+
return {
|
|
405
|
+
type: INVALIDATEALL_TYPE,
|
|
406
|
+
testKey
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function createInvalidate(endpoint, {
|
|
459
411
|
args
|
|
460
412
|
}) {
|
|
461
413
|
return {
|
|
462
|
-
type:
|
|
463
|
-
endpoint
|
|
464
|
-
meta: {
|
|
465
|
-
args,
|
|
466
|
-
key: endpoint.key(...args)
|
|
467
|
-
}
|
|
414
|
+
type: INVALIDATE_TYPE,
|
|
415
|
+
key: endpoint.key(...args)
|
|
468
416
|
};
|
|
469
417
|
}
|
|
470
|
-
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Requesting a fetch to begin
|
|
421
|
+
*/
|
|
422
|
+
function createFetch(endpoint, {
|
|
471
423
|
args
|
|
472
424
|
}) {
|
|
425
|
+
let resolve = 0;
|
|
426
|
+
let reject = 0;
|
|
427
|
+
const promise = new Promise((a, b) => {
|
|
428
|
+
[resolve, reject] = [a, b];
|
|
429
|
+
});
|
|
430
|
+
const meta = {
|
|
431
|
+
fetchedAt: Date.now(),
|
|
432
|
+
resolve,
|
|
433
|
+
reject,
|
|
434
|
+
promise
|
|
435
|
+
};
|
|
473
436
|
return {
|
|
474
|
-
type:
|
|
437
|
+
type: FETCH_TYPE,
|
|
475
438
|
endpoint,
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
439
|
+
args,
|
|
440
|
+
key: endpoint.key(...args),
|
|
441
|
+
meta
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function createExpireAll(testKey) {
|
|
446
|
+
return {
|
|
447
|
+
type: EXPIREALL_TYPE,
|
|
448
|
+
testKey
|
|
480
449
|
};
|
|
481
450
|
}
|
|
482
451
|
|
|
452
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
453
|
+
__proto__: null,
|
|
454
|
+
createSubscription: createSubscription,
|
|
455
|
+
createUnsubscription: createUnsubscription,
|
|
456
|
+
createSetResponse: createSetResponse,
|
|
457
|
+
createSet: createSet,
|
|
458
|
+
createReset: createReset,
|
|
459
|
+
createOptimistic: createOptimistic,
|
|
460
|
+
createMeta: createMeta,
|
|
461
|
+
createInvalidateAll: createInvalidateAll,
|
|
462
|
+
createInvalidate: createInvalidate,
|
|
463
|
+
createFetch: createFetch,
|
|
464
|
+
createExpireAll: createExpireAll
|
|
465
|
+
});
|
|
466
|
+
|
|
483
467
|
function selectMeta(state, fetchKey) {
|
|
484
468
|
return state.meta[fetchKey];
|
|
485
469
|
}
|
|
@@ -532,7 +516,7 @@ class Controller {
|
|
|
532
516
|
});
|
|
533
517
|
this.dispatch(action);
|
|
534
518
|
if (endpoint.schema) {
|
|
535
|
-
return action.meta.promise.then(input => normalizr.denormalize(
|
|
519
|
+
return action.meta.promise.then(input => normalizr.denormalize(endpoint.schema, input, {}, args));
|
|
536
520
|
}
|
|
537
521
|
return action.meta.promise;
|
|
538
522
|
};
|
|
@@ -573,19 +557,6 @@ class Controller {
|
|
|
573
557
|
* @see https://dataclient.io/docs/api/Controller#resetEntireStore
|
|
574
558
|
*/
|
|
575
559
|
this.resetEntireStore = () => this.dispatch(createReset());
|
|
576
|
-
/**
|
|
577
|
-
* Sets value for the Queryable and args.
|
|
578
|
-
* @see https://dataclient.io/docs/api/Controller#set
|
|
579
|
-
*/
|
|
580
|
-
this.set = (schema, ...rest) => {
|
|
581
|
-
const value = rest[rest.length - 1];
|
|
582
|
-
const action = createSet(schema, {
|
|
583
|
-
args: rest.slice(0, rest.length - 1),
|
|
584
|
-
value
|
|
585
|
-
});
|
|
586
|
-
// TODO: reject with error if this fails in reducer
|
|
587
|
-
return this.dispatch(action);
|
|
588
|
-
};
|
|
589
560
|
/**
|
|
590
561
|
* Sets response for the Endpoint and args.
|
|
591
562
|
* @see https://dataclient.io/docs/api/Controller#setResponse
|
|
@@ -612,7 +583,7 @@ class Controller {
|
|
|
612
583
|
return this.dispatch(action);
|
|
613
584
|
};
|
|
614
585
|
/**
|
|
615
|
-
* Resolves an inflight fetch.
|
|
586
|
+
* Resolves an inflight fetch.
|
|
616
587
|
* @see https://dataclient.io/docs/api/Controller#resolve
|
|
617
588
|
*/
|
|
618
589
|
this.resolve = (endpoint, meta) => {
|
|
@@ -650,6 +621,19 @@ class Controller {
|
|
|
650
621
|
this.getState = getState;
|
|
651
622
|
this.memo = memo;
|
|
652
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
* Sets value for the Queryable and args.
|
|
626
|
+
* @see https://dataclient.io/docs/api/Controller#set
|
|
627
|
+
*/
|
|
628
|
+
set(schema, ...rest) {
|
|
629
|
+
const value = rest[rest.length - 1];
|
|
630
|
+
const action = createSet(schema, {
|
|
631
|
+
args: rest.slice(0, rest.length - 1),
|
|
632
|
+
value
|
|
633
|
+
});
|
|
634
|
+
// TODO: reject with error if this fails in reducer
|
|
635
|
+
return this.dispatch(action);
|
|
636
|
+
}
|
|
653
637
|
/**
|
|
654
638
|
* Gets the error, if any, for a given endpoint. Returns undefined for no errors.
|
|
655
639
|
* @see https://dataclient.io/docs/api/Controller#getError
|
|
@@ -687,7 +671,7 @@ class Controller {
|
|
|
687
671
|
const shouldQuery = cacheEndpoints === undefined && schema !== undefined;
|
|
688
672
|
const input = shouldQuery ?
|
|
689
673
|
// nothing in endpoints cache, so try querying if we have a schema to do so
|
|
690
|
-
this.memo.buildQueryKey(
|
|
674
|
+
this.memo.buildQueryKey(schema, args, state.entities, state.indexes, key) : cacheEndpoints;
|
|
691
675
|
if (!isActive) {
|
|
692
676
|
// when not active simply return the query input without denormalizing
|
|
693
677
|
return {
|
|
@@ -712,7 +696,7 @@ class Controller {
|
|
|
712
696
|
const {
|
|
713
697
|
data,
|
|
714
698
|
paths
|
|
715
|
-
} = this.memo.denormalize(
|
|
699
|
+
} = this.memo.denormalize(schema, input, state.entities, args);
|
|
716
700
|
|
|
717
701
|
// note: isInvalid can only be true if shouldQuery is true
|
|
718
702
|
if (!expiresAt && isInvalid) expiresAt = 1;
|
|
@@ -727,10 +711,7 @@ class Controller {
|
|
|
727
711
|
const state = rest[rest.length - 1];
|
|
728
712
|
// this is typescript generics breaking
|
|
729
713
|
const args = rest.slice(0, rest.length - 1).map(ensurePojo$1);
|
|
730
|
-
|
|
731
|
-
// NOTE: different orders can result in cache busting here; but since it's just a perf penalty we will allow for now
|
|
732
|
-
const key = JSON.stringify(args);
|
|
733
|
-
return this.memo.query(key, schema, args, state.entities, state.indexes);
|
|
714
|
+
return this.memo.query(schema, args, state.entities, state.indexes);
|
|
734
715
|
}
|
|
735
716
|
getSchemaResponse(data, paths, entityMeta, expiresAt, invalidIfStale, meta = {}) {
|
|
736
717
|
const invalidDenormalize = typeof data === 'symbol';
|
|
@@ -859,14 +840,14 @@ class NetworkManager {
|
|
|
859
840
|
case SET_RESPONSE_TYPE:
|
|
860
841
|
// only set after new state is computed
|
|
861
842
|
return next(action).then(() => {
|
|
862
|
-
if (action.
|
|
843
|
+
if (action.key in this.fetched) {
|
|
863
844
|
var _controller$getState$;
|
|
864
845
|
// Note: meta *must* be set by reducer so this should be safe
|
|
865
|
-
const error = (_controller$getState$ = controller.getState().meta[action.
|
|
846
|
+
const error = (_controller$getState$ = controller.getState().meta[action.key]) == null ? void 0 : _controller$getState$.error;
|
|
866
847
|
// processing errors result in state meta having error, so we should reject the promise
|
|
867
848
|
if (error) {
|
|
868
849
|
this.handleSet(createSetResponse(action.endpoint, {
|
|
869
|
-
args: action.
|
|
850
|
+
args: action.args,
|
|
870
851
|
response: error,
|
|
871
852
|
fetchedAt: action.meta.fetchedAt,
|
|
872
853
|
error: true
|
|
@@ -900,7 +881,7 @@ class NetworkManager {
|
|
|
900
881
|
/** Used by DevtoolsManager to determine whether to log an action */
|
|
901
882
|
skipLogging(action) {
|
|
902
883
|
/* istanbul ignore next */
|
|
903
|
-
return action.type === FETCH_TYPE && action.
|
|
884
|
+
return action.type === FETCH_TYPE && action.key in this.fetched;
|
|
904
885
|
}
|
|
905
886
|
|
|
906
887
|
/** On mount */
|
|
@@ -944,20 +925,18 @@ class NetworkManager {
|
|
|
944
925
|
* Will then start a promise for a key and potentially start the network
|
|
945
926
|
* fetch.
|
|
946
927
|
*
|
|
947
|
-
* Uses throttle
|
|
928
|
+
* Uses throttle endpoints without sideEffects. This is valuable
|
|
948
929
|
* for ensures mutation requests always go through.
|
|
949
930
|
*/
|
|
950
931
|
handleFetch(action) {
|
|
951
|
-
const fetch = action.payload;
|
|
952
932
|
const {
|
|
953
|
-
key,
|
|
954
|
-
throttle,
|
|
955
933
|
resolve,
|
|
956
934
|
reject,
|
|
957
|
-
|
|
935
|
+
fetchedAt
|
|
958
936
|
} = action.meta;
|
|
937
|
+
const throttle = !action.endpoint.sideEffect;
|
|
959
938
|
const deferedFetch = () => {
|
|
960
|
-
let promise =
|
|
939
|
+
let promise = action.endpoint(...action.args);
|
|
961
940
|
const resolvePromise = promise => promise.then(data => {
|
|
962
941
|
resolve(data);
|
|
963
942
|
return data;
|
|
@@ -971,7 +950,7 @@ class NetworkManager {
|
|
|
971
950
|
if (!throttle) {
|
|
972
951
|
promise = resolvePromise(promise);
|
|
973
952
|
}
|
|
974
|
-
promise = promise.then(
|
|
953
|
+
promise = promise.then(response => {
|
|
975
954
|
let lastReset = this.getLastReset();
|
|
976
955
|
|
|
977
956
|
/* istanbul ignore else */
|
|
@@ -981,22 +960,22 @@ class NetworkManager {
|
|
|
981
960
|
}
|
|
982
961
|
|
|
983
962
|
// don't update state with promises started before last clear
|
|
984
|
-
if (
|
|
963
|
+
if (fetchedAt >= lastReset) {
|
|
985
964
|
this.controller.resolve(action.endpoint, {
|
|
986
|
-
args: action.
|
|
987
|
-
response
|
|
988
|
-
fetchedAt
|
|
965
|
+
args: action.args,
|
|
966
|
+
response,
|
|
967
|
+
fetchedAt
|
|
989
968
|
});
|
|
990
969
|
}
|
|
991
|
-
return
|
|
970
|
+
return response;
|
|
992
971
|
}).catch(error => {
|
|
993
972
|
const lastReset = this.getLastReset();
|
|
994
973
|
// don't update state with promises started before last clear
|
|
995
|
-
if (
|
|
974
|
+
if (fetchedAt >= lastReset) {
|
|
996
975
|
this.controller.resolve(action.endpoint, {
|
|
997
|
-
args: action.
|
|
976
|
+
args: action.args,
|
|
998
977
|
response: error,
|
|
999
|
-
fetchedAt
|
|
978
|
+
fetchedAt,
|
|
1000
979
|
error: true
|
|
1001
980
|
});
|
|
1002
981
|
}
|
|
@@ -1005,7 +984,7 @@ class NetworkManager {
|
|
|
1005
984
|
return promise;
|
|
1006
985
|
};
|
|
1007
986
|
if (throttle) {
|
|
1008
|
-
return this.throttle(key, deferedFetch,
|
|
987
|
+
return this.throttle(action.key, deferedFetch, fetchedAt).then(data => resolve(data)).catch(error => reject(error));
|
|
1009
988
|
} else {
|
|
1010
989
|
return deferedFetch().catch(() => {});
|
|
1011
990
|
}
|
|
@@ -1017,16 +996,16 @@ class NetworkManager {
|
|
|
1017
996
|
*/
|
|
1018
997
|
handleSet(action) {
|
|
1019
998
|
// this can still turn out to be untrue since this is async
|
|
1020
|
-
if (action.
|
|
999
|
+
if (action.key in this.fetched) {
|
|
1021
1000
|
let promiseHandler;
|
|
1022
1001
|
if (action.error) {
|
|
1023
|
-
promiseHandler = this.rejectors[action.
|
|
1002
|
+
promiseHandler = this.rejectors[action.key];
|
|
1024
1003
|
} else {
|
|
1025
|
-
promiseHandler = this.resolvers[action.
|
|
1004
|
+
promiseHandler = this.resolvers[action.key];
|
|
1026
1005
|
}
|
|
1027
|
-
promiseHandler(action.
|
|
1006
|
+
promiseHandler(action.response);
|
|
1028
1007
|
// since we're resolved we no longer need to keep track of this promise
|
|
1029
|
-
this.clear(action.
|
|
1008
|
+
this.clear(action.key);
|
|
1030
1009
|
}
|
|
1031
1010
|
}
|
|
1032
1011
|
|
|
@@ -1051,7 +1030,7 @@ class NetworkManager {
|
|
|
1051
1030
|
* This ensures promises are resolved only once their data is processed
|
|
1052
1031
|
* by the reducer.
|
|
1053
1032
|
*/
|
|
1054
|
-
throttle(key, fetch,
|
|
1033
|
+
throttle(key, fetch, fetchedAt) {
|
|
1055
1034
|
const lastReset = this.getLastReset();
|
|
1056
1035
|
// we're already fetching so reuse the promise
|
|
1057
1036
|
// fetches after reset do not count
|
|
@@ -1062,18 +1041,25 @@ class NetworkManager {
|
|
|
1062
1041
|
this.resolvers[key] = resolve;
|
|
1063
1042
|
this.rejectors[key] = reject;
|
|
1064
1043
|
});
|
|
1065
|
-
this.fetchedAt[key] =
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
RIC$1(() => {
|
|
1044
|
+
this.fetchedAt[key] = fetchedAt;
|
|
1045
|
+
this.idleCallback(() => {
|
|
1046
|
+
// since our real promise is resolved via the wrapReducer(),
|
|
1047
|
+
// we should just stop all errors here.
|
|
1048
|
+
// TODO: decouple this from useFetcher() (that's what's dispatching the error the resolves in here)
|
|
1071
1049
|
fetch().catch(() => null);
|
|
1072
1050
|
}, {
|
|
1073
1051
|
timeout: 500
|
|
1074
1052
|
});
|
|
1075
1053
|
return this.fetched[key];
|
|
1076
1054
|
}
|
|
1055
|
+
|
|
1056
|
+
/** Calls the callback when client is not 'busy' with high priority interaction tasks
|
|
1057
|
+
*
|
|
1058
|
+
* Override for platform-specific implementations
|
|
1059
|
+
*/
|
|
1060
|
+
idleCallback(callback, options) {
|
|
1061
|
+
callback();
|
|
1062
|
+
}
|
|
1077
1063
|
}
|
|
1078
1064
|
|
|
1079
1065
|
function applyManager(managers, controller) {
|
|
@@ -1167,8 +1153,8 @@ class PollingSubscription {
|
|
|
1167
1153
|
if (action.endpoint.pollFrequency === undefined) throw new Error('frequency needed for polling subscription');
|
|
1168
1154
|
this.endpoint = action.endpoint;
|
|
1169
1155
|
this.frequency = action.endpoint.pollFrequency;
|
|
1170
|
-
this.args = action.
|
|
1171
|
-
this.key = action.
|
|
1156
|
+
this.args = action.args;
|
|
1157
|
+
this.key = action.key;
|
|
1172
1158
|
this.frequencyHistogram.set(this.frequency, 1);
|
|
1173
1159
|
this.controller = controller;
|
|
1174
1160
|
this.connectionListener = connectionListener || new DefaultConnectionListener$1();
|
|
@@ -1330,7 +1316,7 @@ class SubscriptionManager {
|
|
|
1330
1316
|
*
|
|
1331
1317
|
*/
|
|
1332
1318
|
handleSubscribe(action) {
|
|
1333
|
-
const key = action.
|
|
1319
|
+
const key = action.key;
|
|
1334
1320
|
if (key in this.subscriptions) {
|
|
1335
1321
|
const frequency = action.endpoint.pollFrequency;
|
|
1336
1322
|
this.subscriptions[key].add(frequency);
|
|
@@ -1343,7 +1329,7 @@ class SubscriptionManager {
|
|
|
1343
1329
|
*
|
|
1344
1330
|
*/
|
|
1345
1331
|
handleUnsubscribe(action) {
|
|
1346
|
-
const key = action.
|
|
1332
|
+
const key = action.key;
|
|
1347
1333
|
|
|
1348
1334
|
/* istanbul ignore else */
|
|
1349
1335
|
if (key in this.subscriptions) {
|
|
@@ -1526,7 +1512,7 @@ class LogoutManager {
|
|
|
1526
1512
|
if (shouldLogout) this.shouldLogout = shouldLogout;
|
|
1527
1513
|
this.middleware = controller => next => async action => {
|
|
1528
1514
|
await next(action);
|
|
1529
|
-
if (action.type === SET_RESPONSE_TYPE && action.error && this.shouldLogout(action.
|
|
1515
|
+
if (action.type === SET_RESPONSE_TYPE && action.error && this.shouldLogout(action.response)) {
|
|
1530
1516
|
this.handleLogout(controller);
|
|
1531
1517
|
}
|
|
1532
1518
|
};
|
|
@@ -1564,9 +1550,7 @@ exports.ResetError = ResetError;
|
|
|
1564
1550
|
exports.SubscriptionManager = SubscriptionManager;
|
|
1565
1551
|
exports.__INTERNAL__ = internal;
|
|
1566
1552
|
exports.actionTypes = actionTypes;
|
|
1553
|
+
exports.actions = index;
|
|
1567
1554
|
exports.applyManager = applyManager;
|
|
1568
|
-
exports.createFetch = createFetch;
|
|
1569
1555
|
exports.createReducer = createReducer;
|
|
1570
|
-
exports.createSet = createSet;
|
|
1571
|
-
exports.createSetResponse = createSetResponse;
|
|
1572
1556
|
exports.initialState = initialState;
|