@lowentry/react-redux 1.9.1 → 1.10.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/index.js +208 -143
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeRed.jsx +158 -75
package/index.js
CHANGED
|
@@ -399,7 +399,7 @@ var LeRed = function () {
|
|
|
399
399
|
case 0:
|
|
400
400
|
_context5.next = 2;
|
|
401
401
|
return ReduxSagaEffects.takeEvery(reducerAction, /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(action) {
|
|
402
|
-
var promiseResolve, promiseReject,
|
|
402
|
+
var promiseResolve, promiseReject, _promise, result;
|
|
403
403
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
404
404
|
while (1) switch (_context4.prev = _context4.next) {
|
|
405
405
|
case 0:
|
|
@@ -407,16 +407,16 @@ var LeRed = function () {
|
|
|
407
407
|
promiseReject = null;
|
|
408
408
|
_context4.prev = 2;
|
|
409
409
|
if (action.__lowentry_dispatch__ === true) {
|
|
410
|
-
|
|
410
|
+
_promise = new Promise(function (resolve, reject) {
|
|
411
411
|
promiseResolve = resolve;
|
|
412
412
|
promiseReject = reject;
|
|
413
413
|
});
|
|
414
414
|
if (Array.isArray(action.__lowentry_dispatch_result__)) {
|
|
415
|
-
if (typeof
|
|
416
|
-
action.__lowentry_dispatch_result__.push(
|
|
415
|
+
if (typeof _promise !== 'undefined') {
|
|
416
|
+
action.__lowentry_dispatch_result__.push(_promise);
|
|
417
417
|
}
|
|
418
418
|
} else {
|
|
419
|
-
action.__lowentry_dispatch_result__ =
|
|
419
|
+
action.__lowentry_dispatch_result__ = _promise;
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
_context4.next = 6;
|
|
@@ -618,7 +618,7 @@ var LeRed = function () {
|
|
|
618
618
|
return LeRed.useEffect(function () {
|
|
619
619
|
var stop = false;
|
|
620
620
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
621
|
-
var _iterator, _step,
|
|
621
|
+
var _iterator, _step, _promise2;
|
|
622
622
|
return _regeneratorRuntime.wrap(function _callee5$(_context6) {
|
|
623
623
|
while (1) switch (_context6.prev = _context6.next) {
|
|
624
624
|
case 0:
|
|
@@ -630,7 +630,7 @@ var LeRed = function () {
|
|
|
630
630
|
_context6.next = 13;
|
|
631
631
|
break;
|
|
632
632
|
}
|
|
633
|
-
|
|
633
|
+
_promise2 = _step.value;
|
|
634
634
|
if (!stop) {
|
|
635
635
|
_context6.next = 7;
|
|
636
636
|
break;
|
|
@@ -638,7 +638,7 @@ var LeRed = function () {
|
|
|
638
638
|
return _context6.abrupt("return");
|
|
639
639
|
case 7:
|
|
640
640
|
_context6.next = 9;
|
|
641
|
-
return
|
|
641
|
+
return _promise2;
|
|
642
642
|
case 9:
|
|
643
643
|
if (!stop) {
|
|
644
644
|
_context6.next = 11;
|
|
@@ -674,7 +674,7 @@ var LeRed = function () {
|
|
|
674
674
|
return LeRed.useEffect(function () {
|
|
675
675
|
var stop = false;
|
|
676
676
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
677
|
-
var _iterator2, _step2,
|
|
677
|
+
var _iterator2, _step2, _promise3;
|
|
678
678
|
return _regeneratorRuntime.wrap(function _callee6$(_context7) {
|
|
679
679
|
while (1) switch (_context7.prev = _context7.next) {
|
|
680
680
|
case 0:
|
|
@@ -690,7 +690,7 @@ var LeRed = function () {
|
|
|
690
690
|
_context7.next = 14;
|
|
691
691
|
break;
|
|
692
692
|
}
|
|
693
|
-
|
|
693
|
+
_promise3 = _step2.value;
|
|
694
694
|
if (!stop) {
|
|
695
695
|
_context7.next = 8;
|
|
696
696
|
break;
|
|
@@ -698,7 +698,7 @@ var LeRed = function () {
|
|
|
698
698
|
return _context7.abrupt("return");
|
|
699
699
|
case 8:
|
|
700
700
|
_context7.next = 10;
|
|
701
|
-
return
|
|
701
|
+
return _promise3;
|
|
702
702
|
case 10:
|
|
703
703
|
if (!stop) {
|
|
704
704
|
_context7.next = 12;
|
|
@@ -1100,7 +1100,7 @@ var LeRed = function () {
|
|
|
1100
1100
|
setImageUrl(url + (urlHasQ ? '&' : '?') + ((options === null || options === void 0 ? void 0 : options.queryParam) || 'lowentryretryingimgversion') + '=' + retries.current++);
|
|
1101
1101
|
}, typeof (options === null || options === void 0 ? void 0 : options.delay) === 'function' ? INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay(retries.current), defaultDelay) : INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay, defaultDelay));
|
|
1102
1102
|
}
|
|
1103
|
-
}, [url]);
|
|
1103
|
+
}, [url, options]);
|
|
1104
1104
|
var onImageLoadErrorIgnored = LeRed.useCallback(function () {}, []);
|
|
1105
1105
|
if (!url) {
|
|
1106
1106
|
return [url, onImageLoadErrorIgnored];
|
|
@@ -1109,13 +1109,17 @@ var LeRed = function () {
|
|
|
1109
1109
|
};
|
|
1110
1110
|
|
|
1111
1111
|
/**
|
|
1112
|
-
* Allows you to easily
|
|
1112
|
+
* Allows you to easily convert promises to react hooks.
|
|
1113
|
+
*
|
|
1114
|
+
* The given callable should return promises. The returned promises can be an array, an object, or even a single promise. The returned data of this hook will match the promises it has operated on.
|
|
1115
|
+
*
|
|
1116
|
+
* The given comparingValues can be anything, this is used to detect whether the given promises have changed or not, and so whether new promises have to be generated and executed again.
|
|
1113
1117
|
*/
|
|
1114
|
-
LeRed.
|
|
1115
|
-
var
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1118
|
+
LeRed.usePromises = function (callable, comparingValues) {
|
|
1119
|
+
var comparingValuesClone = LeUtils.clone(comparingValues);
|
|
1120
|
+
var comparingValuesRef = LeRed.useRef(comparingValuesClone);
|
|
1121
|
+
var latestComparingValuesRef = LeRed.useRef();
|
|
1122
|
+
latestComparingValuesRef.current = comparingValuesClone;
|
|
1119
1123
|
var _LeRed$useState11 = LeRed.useState(null),
|
|
1120
1124
|
_LeRed$useState12 = _slicedToArray(_LeRed$useState11, 2),
|
|
1121
1125
|
data = _LeRed$useState12[0],
|
|
@@ -1132,167 +1136,228 @@ var LeRed = function () {
|
|
|
1132
1136
|
setLoading(true);
|
|
1133
1137
|
setData(null);
|
|
1134
1138
|
setError(null);
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1139
|
+
try {
|
|
1140
|
+
var promises = callable();
|
|
1141
|
+
var promisesKeyed = [];
|
|
1142
|
+
if (IS_OBJECT(promises) || IS_ARRAY(promises)) {
|
|
1143
|
+
LeUtils.each(promises, function (urlString, key) {
|
|
1144
|
+
promisesKeyed.push({
|
|
1145
|
+
promise: promise,
|
|
1146
|
+
key: key
|
|
1147
|
+
});
|
|
1148
|
+
});
|
|
1149
|
+
} else {
|
|
1150
|
+
promisesKeyed.push({
|
|
1151
|
+
promises: promises,
|
|
1152
|
+
key: undefined
|
|
1141
1153
|
});
|
|
1154
|
+
}
|
|
1155
|
+
var wrappedPromises = [];
|
|
1156
|
+
LeUtils.each(promisesKeyed, function (_ref3) {
|
|
1157
|
+
var promise = _ref3.promise,
|
|
1158
|
+
key = _ref3.key;
|
|
1159
|
+
wrappedPromises.push(promise.then( /*#__PURE__*/function () {
|
|
1160
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(result) {
|
|
1161
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context8) {
|
|
1162
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1163
|
+
case 0:
|
|
1164
|
+
return _context8.abrupt("return", {
|
|
1165
|
+
result: result,
|
|
1166
|
+
key: key
|
|
1167
|
+
});
|
|
1168
|
+
case 1:
|
|
1169
|
+
case "end":
|
|
1170
|
+
return _context8.stop();
|
|
1171
|
+
}
|
|
1172
|
+
}, _callee7);
|
|
1173
|
+
}));
|
|
1174
|
+
return function (_x) {
|
|
1175
|
+
return _ref4.apply(this, arguments);
|
|
1176
|
+
};
|
|
1177
|
+
}()));
|
|
1142
1178
|
});
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1179
|
+
Promise.all(wrappedPromises).then(function (resultObjects) {
|
|
1180
|
+
var _resultObjects$pop;
|
|
1181
|
+
if (IS_OBJECT(promises)) {
|
|
1182
|
+
var results = {};
|
|
1183
|
+
LeUtils.each(resultObjects, function (_ref5) {
|
|
1184
|
+
var result = _ref5.result,
|
|
1185
|
+
key = _ref5.key;
|
|
1186
|
+
results[key] = result;
|
|
1187
|
+
});
|
|
1188
|
+
return results;
|
|
1189
|
+
} else if (IS_ARRAY(promises)) {
|
|
1190
|
+
var _results = [];
|
|
1191
|
+
LeUtils.each(resultObjects, function (_ref6) {
|
|
1192
|
+
var result = _ref6.result,
|
|
1193
|
+
key = _ref6.key;
|
|
1194
|
+
_results[key] = result;
|
|
1195
|
+
});
|
|
1196
|
+
return _results;
|
|
1197
|
+
}
|
|
1198
|
+
return (_resultObjects$pop = resultObjects.pop()) === null || _resultObjects$pop === void 0 ? void 0 : _resultObjects$pop.result;
|
|
1199
|
+
}).then(function (results) {
|
|
1200
|
+
if (!LeUtils.equals(latestComparingValuesRef.current, comparingValuesClone)) {
|
|
1201
|
+
// canceled
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
comparingValuesRef.current = comparingValuesClone;
|
|
1205
|
+
setLoading(false);
|
|
1206
|
+
setData(results);
|
|
1207
|
+
setError(null);
|
|
1208
|
+
})["catch"](function (error) {
|
|
1209
|
+
if (!LeUtils.equals(latestComparingValuesRef.current, comparingValuesClone)) {
|
|
1210
|
+
// canceled
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
comparingValuesRef.current = comparingValuesClone;
|
|
1214
|
+
setLoading(false);
|
|
1215
|
+
setData(null);
|
|
1216
|
+
setError(LeUtils.purgeErrorMessage(error));
|
|
1217
|
+
});
|
|
1218
|
+
return function () {
|
|
1219
|
+
LeUtils.each(wrappedPromises, function (promise) {
|
|
1220
|
+
try {
|
|
1221
|
+
var _promise$cancel;
|
|
1222
|
+
promise === null || promise === void 0 || (_promise$cancel = promise.cancel) === null || _promise$cancel === void 0 || _promise$cancel.call(promise);
|
|
1223
|
+
} catch (e) {
|
|
1224
|
+
console.error('Failed to cancel the given promise:', e);
|
|
1225
|
+
}
|
|
1226
|
+
try {
|
|
1227
|
+
var _promise$remove;
|
|
1228
|
+
promise === null || promise === void 0 || (_promise$remove = promise.remove) === null || _promise$remove === void 0 || _promise$remove.call(promise);
|
|
1229
|
+
} catch (e) {
|
|
1230
|
+
console.error('Failed to remove the given promise:', e);
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
};
|
|
1234
|
+
} catch (error) {
|
|
1235
|
+
LeUtils.setAnimationFrameTimeout(function () {
|
|
1236
|
+
if (!LeUtils.equals(latestComparingValuesRef.current, comparingValuesClone)) {
|
|
1237
|
+
// canceled
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
comparingValuesRef.current = comparingValuesClone;
|
|
1241
|
+
setLoading(false);
|
|
1242
|
+
setData(null);
|
|
1243
|
+
setError(LeUtils.purgeErrorMessage(error));
|
|
1147
1244
|
});
|
|
1148
1245
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1246
|
+
}, [comparingValuesClone]);
|
|
1247
|
+
if (!LeUtils.equals(comparingValuesRef.current, comparingValuesClone)) {
|
|
1248
|
+
return [null, true, null];
|
|
1249
|
+
}
|
|
1250
|
+
return [data, loading, error];
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* Allows you to easily obtain external data.
|
|
1255
|
+
*/
|
|
1256
|
+
LeRed.useExternal = function (url, options, responseFunction) {
|
|
1257
|
+
return LeRed.usePromises(function () {
|
|
1258
|
+
var createFetch = function createFetch(urlString) {
|
|
1259
|
+
return LeUtils.fetch(STRING(urlString), _objectSpread({
|
|
1154
1260
|
retries: 3
|
|
1155
1261
|
}, options !== null && options !== void 0 ? options : {})).then( /*#__PURE__*/function () {
|
|
1156
|
-
var
|
|
1262
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(response) {
|
|
1157
1263
|
var data;
|
|
1158
|
-
return _regeneratorRuntime.wrap(function
|
|
1159
|
-
while (1) switch (
|
|
1264
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context9) {
|
|
1265
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1160
1266
|
case 0:
|
|
1161
|
-
|
|
1162
|
-
return
|
|
1267
|
+
_context9.next = 2;
|
|
1268
|
+
return responseFunction(response);
|
|
1163
1269
|
case 2:
|
|
1164
|
-
data =
|
|
1270
|
+
data = _context9.sent;
|
|
1165
1271
|
if (!(typeof (options === null || options === void 0 ? void 0 : options.verify) === 'function')) {
|
|
1166
|
-
|
|
1272
|
+
_context9.next = 6;
|
|
1167
1273
|
break;
|
|
1168
1274
|
}
|
|
1169
|
-
|
|
1275
|
+
_context9.next = 6;
|
|
1170
1276
|
return options.verify(data, response);
|
|
1171
1277
|
case 6:
|
|
1172
|
-
return
|
|
1173
|
-
data: data,
|
|
1174
|
-
key: key
|
|
1175
|
-
});
|
|
1278
|
+
return _context9.abrupt("return", data);
|
|
1176
1279
|
case 7:
|
|
1177
1280
|
case "end":
|
|
1178
|
-
return
|
|
1281
|
+
return _context9.stop();
|
|
1179
1282
|
}
|
|
1180
|
-
},
|
|
1283
|
+
}, _callee8);
|
|
1181
1284
|
}));
|
|
1182
|
-
return function (
|
|
1183
|
-
return
|
|
1285
|
+
return function (_x2) {
|
|
1286
|
+
return _ref7.apply(this, arguments);
|
|
1184
1287
|
};
|
|
1185
|
-
}())
|
|
1186
|
-
});
|
|
1187
|
-
Promise.all(fetches).then(function (values) {
|
|
1188
|
-
var _values$pop;
|
|
1189
|
-
if (IS_OBJECT(url)) {
|
|
1190
|
-
var result = {};
|
|
1191
|
-
LeUtils.each(values, function (_ref5) {
|
|
1192
|
-
var data = _ref5.data,
|
|
1193
|
-
key = _ref5.key;
|
|
1194
|
-
result[key] = data;
|
|
1195
|
-
});
|
|
1196
|
-
return result;
|
|
1197
|
-
} else if (IS_ARRAY(url)) {
|
|
1198
|
-
var _result = [];
|
|
1199
|
-
LeUtils.each(values, function (_ref6) {
|
|
1200
|
-
var data = _ref6.data,
|
|
1201
|
-
key = _ref6.key;
|
|
1202
|
-
_result[key] = data;
|
|
1203
|
-
});
|
|
1204
|
-
return _result;
|
|
1205
|
-
}
|
|
1206
|
-
return (_values$pop = values.pop()) === null || _values$pop === void 0 ? void 0 : _values$pop.data;
|
|
1207
|
-
}).then(function (data) {
|
|
1208
|
-
paramsRef.current = {
|
|
1209
|
-
url: url,
|
|
1210
|
-
options: options
|
|
1211
|
-
};
|
|
1212
|
-
setLoading(false);
|
|
1213
|
-
setData(data);
|
|
1214
|
-
setError(null);
|
|
1215
|
-
})["catch"](function (error) {
|
|
1216
|
-
paramsRef.current = {
|
|
1217
|
-
url: url,
|
|
1218
|
-
options: options
|
|
1219
|
-
};
|
|
1220
|
-
setLoading(false);
|
|
1221
|
-
setData(null);
|
|
1222
|
-
setError(LeUtils.purgeErrorMessage(error));
|
|
1223
|
-
});
|
|
1224
|
-
return function () {
|
|
1225
|
-
LeUtils.each(fetches, function (fetch) {
|
|
1226
|
-
fetch.remove();
|
|
1227
|
-
});
|
|
1288
|
+
}());
|
|
1228
1289
|
};
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1290
|
+
if (IS_OBJECT(url)) {
|
|
1291
|
+
var promises = {};
|
|
1292
|
+
LeUtils.each(url, function (urlString, key) {
|
|
1293
|
+
promises[key] = createFetch(urlString);
|
|
1294
|
+
});
|
|
1295
|
+
return promises;
|
|
1296
|
+
}
|
|
1297
|
+
if (IS_ARRAY(url)) {
|
|
1298
|
+
var _promises = [];
|
|
1299
|
+
LeUtils.each(url, function (urlString) {
|
|
1300
|
+
_promises.push(createFetch(urlString));
|
|
1301
|
+
});
|
|
1302
|
+
return _promises;
|
|
1303
|
+
}
|
|
1304
|
+
return createFetch(url);
|
|
1305
|
+
}, [url, options, responseFunction]);
|
|
1237
1306
|
};
|
|
1238
1307
|
|
|
1239
1308
|
/**
|
|
1240
1309
|
* Allows you to easily obtain external JSON data.
|
|
1241
1310
|
*/
|
|
1242
1311
|
LeRed.useExternalJson = function (url, options) {
|
|
1243
|
-
|
|
1312
|
+
var responseFunction = LeRed.useCallback(function (response) {
|
|
1244
1313
|
return response.json();
|
|
1245
|
-
});
|
|
1314
|
+
}, []);
|
|
1315
|
+
return LeRed.useExternal(url, options, responseFunction);
|
|
1246
1316
|
};
|
|
1247
1317
|
|
|
1248
1318
|
/**
|
|
1249
1319
|
* Allows you to easily obtain external Blob data.
|
|
1250
1320
|
*/
|
|
1251
1321
|
LeRed.useExternalBlob = function (url, options) {
|
|
1252
|
-
|
|
1322
|
+
var responseFunction = LeRed.useCallback(function (response) {
|
|
1253
1323
|
return response.blob();
|
|
1254
|
-
});
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
/**
|
|
1258
|
-
* Allows you to easily obtain external Uint8Array data.
|
|
1259
|
-
*/
|
|
1260
|
-
LeRed.useExternalBytes = function (url, options) {
|
|
1261
|
-
return LeRed.useExternal(url, options, function (response) {
|
|
1262
|
-
return response.bytes();
|
|
1263
|
-
});
|
|
1324
|
+
}, []);
|
|
1325
|
+
return LeRed.useExternal(url, options, responseFunction);
|
|
1264
1326
|
};
|
|
1265
1327
|
|
|
1266
1328
|
/**
|
|
1267
1329
|
* Allows you to easily obtain external ArrayBuffer data.
|
|
1268
1330
|
*/
|
|
1269
1331
|
LeRed.useExternalArrayBuffer = function (url, options) {
|
|
1270
|
-
|
|
1332
|
+
var responseFunction = LeRed.useCallback(function (response) {
|
|
1271
1333
|
return response.arrayBuffer();
|
|
1272
|
-
});
|
|
1334
|
+
}, []);
|
|
1335
|
+
return LeRed.useExternal(url, options, responseFunction);
|
|
1273
1336
|
};
|
|
1274
1337
|
|
|
1275
1338
|
/**
|
|
1276
1339
|
* Allows you to easily obtain external string data.
|
|
1277
1340
|
*/
|
|
1278
1341
|
LeRed.useExternalString = function (url, options) {
|
|
1279
|
-
|
|
1342
|
+
var responseFunction = LeRed.useCallback(function (response) {
|
|
1280
1343
|
return response.text();
|
|
1281
|
-
});
|
|
1344
|
+
}, []);
|
|
1345
|
+
return LeRed.useExternal(url, options, responseFunction);
|
|
1282
1346
|
};
|
|
1283
1347
|
|
|
1284
1348
|
/**
|
|
1285
1349
|
* Allows you to easily obtain external form data.
|
|
1286
1350
|
*/
|
|
1287
1351
|
LeRed.useExternalFormData = function (url, options) {
|
|
1288
|
-
|
|
1352
|
+
var responseFunction = LeRed.useCallback(function (response) {
|
|
1289
1353
|
return response.formData();
|
|
1290
|
-
});
|
|
1354
|
+
}, []);
|
|
1355
|
+
return LeRed.useExternal(url, options, responseFunction);
|
|
1291
1356
|
};
|
|
1292
|
-
LeRed.Root = LeRed.memo(function (
|
|
1293
|
-
var store =
|
|
1294
|
-
children =
|
|
1295
|
-
other = _objectWithoutProperties(
|
|
1357
|
+
LeRed.Root = LeRed.memo(function (_ref8) {
|
|
1358
|
+
var store = _ref8.store,
|
|
1359
|
+
children = _ref8.children,
|
|
1360
|
+
other = _objectWithoutProperties(_ref8, _excluded);
|
|
1296
1361
|
if (ISSET(store)) {
|
|
1297
1362
|
store = LeRed.configureStore(store);
|
|
1298
1363
|
return /*#__PURE__*/React.createElement(ReactRedux.Provider, _extends({
|
|
@@ -1303,57 +1368,57 @@ var LeRed = function () {
|
|
|
1303
1368
|
});
|
|
1304
1369
|
LeRed.PreloadComponent = function (load) {
|
|
1305
1370
|
if (typeof window !== 'undefined') {
|
|
1306
|
-
var
|
|
1371
|
+
var _promise4 = load(); // start loading already, before it's being rendered in React
|
|
1307
1372
|
return function () {
|
|
1308
|
-
return
|
|
1373
|
+
return _promise4;
|
|
1309
1374
|
};
|
|
1310
1375
|
}
|
|
1311
1376
|
return load;
|
|
1312
1377
|
};
|
|
1313
|
-
LeRed.LoadComponent = LeRed.memo(function (
|
|
1314
|
-
var loading =
|
|
1315
|
-
load =
|
|
1316
|
-
other = _objectWithoutProperties(
|
|
1378
|
+
LeRed.LoadComponent = LeRed.memo(function (_ref9) {
|
|
1379
|
+
var loading = _ref9.loading,
|
|
1380
|
+
load = _ref9.load,
|
|
1381
|
+
other = _objectWithoutProperties(_ref9, _excluded2);
|
|
1317
1382
|
var _LeRed$useState17 = LeRed.useState(loading !== null && loading !== void 0 ? loading : null),
|
|
1318
1383
|
_LeRed$useState18 = _slicedToArray(_LeRed$useState17, 2),
|
|
1319
1384
|
Component = _LeRed$useState18[0],
|
|
1320
1385
|
setComponent = _LeRed$useState18[1];
|
|
1321
1386
|
LeRed.useEffect(function () {
|
|
1322
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1387
|
+
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
1323
1388
|
var LoadedComponent;
|
|
1324
|
-
return _regeneratorRuntime.wrap(function
|
|
1325
|
-
while (1) switch (
|
|
1389
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context10) {
|
|
1390
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1326
1391
|
case 0:
|
|
1327
1392
|
if (!(typeof load === 'function')) {
|
|
1328
|
-
|
|
1393
|
+
_context10.next = 6;
|
|
1329
1394
|
break;
|
|
1330
1395
|
}
|
|
1331
|
-
|
|
1396
|
+
_context10.next = 3;
|
|
1332
1397
|
return load();
|
|
1333
1398
|
case 3:
|
|
1334
|
-
|
|
1335
|
-
|
|
1399
|
+
_context10.t0 = _context10.sent;
|
|
1400
|
+
_context10.next = 9;
|
|
1336
1401
|
break;
|
|
1337
1402
|
case 6:
|
|
1338
|
-
|
|
1403
|
+
_context10.next = 8;
|
|
1339
1404
|
return load;
|
|
1340
1405
|
case 8:
|
|
1341
|
-
|
|
1406
|
+
_context10.t0 = _context10.sent;
|
|
1342
1407
|
case 9:
|
|
1343
|
-
LoadedComponent =
|
|
1408
|
+
LoadedComponent = _context10.t0;
|
|
1344
1409
|
if (LoadedComponent) {
|
|
1345
|
-
|
|
1410
|
+
_context10.next = 13;
|
|
1346
1411
|
break;
|
|
1347
1412
|
}
|
|
1348
1413
|
setComponent(null);
|
|
1349
|
-
return
|
|
1414
|
+
return _context10.abrupt("return");
|
|
1350
1415
|
case 13:
|
|
1351
1416
|
setComponent( /*#__PURE__*/React.createElement(LoadedComponent, other));
|
|
1352
1417
|
case 14:
|
|
1353
1418
|
case "end":
|
|
1354
|
-
return
|
|
1419
|
+
return _context10.stop();
|
|
1355
1420
|
}
|
|
1356
|
-
},
|
|
1421
|
+
}, _callee9);
|
|
1357
1422
|
}))();
|
|
1358
1423
|
}, []);
|
|
1359
1424
|
return Component;
|