UNPKG

3.19 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.clearAsync = exports.delAsyncEntry = exports.setAsyncFailure = exports.setAsyncSuccess = exports.setAsyncRequest = exports.FAILURE = exports.SUCCESS = exports.REQUEST = void 0;
9
10var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
11
12var _objectSpread5 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectSpread"));
13
14var _lodash = _interopRequireDefault(require("lodash.curryright"));
15
16var REQUEST = 'REQUEST';
17exports.REQUEST = REQUEST;
18var SUCCESS = 'SUCCESS';
19exports.SUCCESS = SUCCESS;
20var FAILURE = 'FAILURE';
21exports.FAILURE = FAILURE;
22
23var del = function del(state, key) {
24 var newState = (0, _objectSpread5.default)({}, state);
25 delete newState[key];
26 return newState;
27};
28
29var 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});
38exports.setAsyncRequest = setAsyncRequest;
39var 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});
48exports.setAsyncSuccess = setAsyncSuccess;
49var 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});
58exports.setAsyncFailure = setAsyncFailure;
59
60var 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
74exports.delAsyncEntry = delAsyncEntry;
75
76var 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
83exports.clearAsync = clearAsync;
\No newline at end of file