1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.clearAsync = exports.delAsyncEntry = exports.setAsyncFailure = exports.setAsyncSuccess = exports.setAsyncRequest = exports.FAILURE = exports.SUCCESS = exports.REQUEST = void 0;
|
9 |
|
10 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
11 |
|
12 | var _objectSpread5 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectSpread"));
|
13 |
|
14 | var _lodash = _interopRequireDefault(require("lodash.curryright"));
|
15 |
|
16 | var REQUEST = 'REQUEST';
|
17 | exports.REQUEST = REQUEST;
|
18 | var SUCCESS = 'SUCCESS';
|
19 | exports.SUCCESS = SUCCESS;
|
20 | var FAILURE = 'FAILURE';
|
21 | exports.FAILURE = FAILURE;
|
22 |
|
23 | var del = function del(state, key) {
|
24 | var newState = (0, _objectSpread5.default)({}, state);
|
25 | delete newState[key];
|
26 | return newState;
|
27 | };
|
28 |
|
29 | var setAsyncRequest = (0, _lodash.default)(function (asyncState, params) {
|
30 | var _params$status;
|
31 |
|
32 | if (params.useStatus === false && params.status) {
|
33 | throw Error('setAsyncRequest cannot have both a status option and a useStatus set to false');
|
34 | }
|
35 |
|
36 | return (0, _objectSpread5.default)({}, asyncState, (0, _defineProperty2.default)({}, params.key, params.useStatus || params.status ? (_params$status = params.status) !== null && _params$status !== void 0 ? _params$status : REQUEST : true));
|
37 | });
|
38 | exports.setAsyncRequest = setAsyncRequest;
|
39 | var setAsyncSuccess = (0, _lodash.default)(function (asyncState, params) {
|
40 | var _params$status2;
|
41 |
|
42 | if (params.useStatus === false && params.status) {
|
43 | throw Error('setAsyncSuccess cannot have both a status option and a useStatus set to false');
|
44 | }
|
45 |
|
46 | return params.useStatus || params.status ? (0, _objectSpread5.default)({}, asyncState, (0, _defineProperty2.default)({}, params.key, (_params$status2 = params.status) !== null && _params$status2 !== void 0 ? _params$status2 : SUCCESS)) : del(asyncState, params.key);
|
47 | });
|
48 | exports.setAsyncSuccess = setAsyncSuccess;
|
49 | var setAsyncFailure = (0, _lodash.default)(function (asyncState, params) {
|
50 | var _params$status3;
|
51 |
|
52 | if (params.useStatus === false && params.status) {
|
53 | throw Error('setAsyncFailure cannot have both a status option and a useStatus set to false');
|
54 | }
|
55 |
|
56 | return params.useStatus || params.status ? (0, _objectSpread5.default)({}, asyncState, (0, _defineProperty2.default)({}, params.key, (_params$status3 = params.status) !== null && _params$status3 !== void 0 ? _params$status3 : FAILURE)) : del(asyncState, params.key);
|
57 | });
|
58 | exports.setAsyncFailure = setAsyncFailure;
|
59 |
|
60 | var delAsyncEntry = function delAsyncEntry(key) {
|
61 | if (!key) {
|
62 | throw Error('delAsyncEntry() requires a key argument');
|
63 | }
|
64 |
|
65 | if (typeof key === 'string') {
|
66 | return function (state) {
|
67 | return del(state, key);
|
68 | };
|
69 | }
|
70 |
|
71 | throw Error('Incorrect parameters for delAsyncEntry()');
|
72 | };
|
73 |
|
74 | exports.delAsyncEntry = delAsyncEntry;
|
75 |
|
76 | var clearAsync = function clearAsync(key // flow-disable-next-line
|
77 | ) {
|
78 | return typeof key === 'string' ? function (state) {
|
79 | return (0, _defineProperty2.default)({}, key, state[key]);
|
80 | } : {};
|
81 | };
|
82 |
|
83 | exports.clearAsync = clearAsync; |
\ | No newline at end of file |