@rest-api/react-models
Version:
[](https://www.npmjs.com/package/@rest-api/react-models) [](https://codecov.io/gh/hector7/rest-
92 lines (91 loc) • 2.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.shouldFetch = exports.restActions = exports.idActions = exports.REMOVE_ID = exports.RECEIVE_ID = exports.INVALIDATE_ID = exports.FAILED_ID = exports.REQUEST_ID = exports.RECEIVE = exports.INVALIDATE_ALL = exports.INVALIDATE = exports.FAILED = exports.REQUEST = exports.IGNORED_STATUS = void 0;
const utils_1 = require("../reducers/utils");
const __1 = require("../..");
exports.IGNORED_STATUS = [408];
exports.REQUEST = 'REQUEST';
exports.FAILED = 'FAILED';
exports.INVALIDATE = 'INVALIDATE';
exports.INVALIDATE_ALL = 'INVALIDATE_ALL';
exports.RECEIVE = 'RECEIVE';
exports.REQUEST_ID = 'REQUEST_ID';
exports.FAILED_ID = 'FAILED_ID';
exports.INVALIDATE_ID = 'INVALIDATE_ID';
exports.RECEIVE_ID = 'RECEIVE_ID';
exports.REMOVE_ID = 'REMOVE_ID';
exports.idActions = {
invalidateAll: (reducerName, optKey = '') => __1.createAction(exports.INVALIDATE_ALL, {
reducerName,
optKey
}),
fetchByIdIfNeeded: (reducerName, idKey, id, optKey = '') => __1.createAction(exports.REQUEST_ID, {
idKey,
reducerName,
id,
optKey
}),
failedById: (reducerName, idKey, id, error, optKey = '') => __1.createAction(exports.FAILED_ID, {
idKey,
reducerName,
id,
error,
optKey
}),
invalidateById: (reducerName, idKey, id, optKey = '') => __1.createAction(exports.INVALIDATE_ID, {
idKey,
reducerName,
id,
optKey
}),
receiveById: function (reducerName, data, optKey = '') {
return __1.createAction(exports.RECEIVE_ID, {
reducerName,
data,
optKey
});
},
removeById: function (reducerName, idKey, data, optKey = '') {
return __1.createAction(exports.REMOVE_ID, {
idKey,
reducerName,
data,
id: data[idKey],
optKey
});
},
};
exports.restActions = {
request: (reducerName, uri, optKey = '') => __1.createAction(exports.REQUEST, {
uri,
reducerName,
optKey
}),
failed: (reducerName, uri, error, optKey = '') => __1.createAction(exports.FAILED, {
uri,
reducerName,
error,
optKey
}),
invalidate: (reducerName, uri, optKey = '') => __1.createAction(exports.INVALIDATE, {
uri,
reducerName,
optKey
}),
receive: function (idKey, reducerName, uri, items, metadata, optKey = '') {
return __1.createAction(exports.RECEIVE, {
idKey,
reducerName,
uri,
items,
metadata,
optKey
});
},
};
function shouldFetch(request) {
if (utils_1.isFetching(request))
return false;
return utils_1.isInvalidated(request);
}
exports.shouldFetch = shouldFetch;