This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/actions/buildAsyncAction.js

30 lines
731 B
JavaScript
Raw Normal View History

2016-04-28 17:34:20 +01:00
import { CALL_API } from 'redux-api-middleware';
import _ from 'underscore';
export default function buildRsaAction(actionSet, path, method, optionalData, meta) {
const types = _.map([actionSet.REQUEST, actionSet.SUCCESS, actionSet.FAILURE], (requestType) => {
if (meta) {
return { type: requestType, meta: _.clone(meta) };
}
return { type: requestType };
});
let actionData = {
types: types,
endpoint: path,
method,
headers: {
'Accept': 'application/json'
},
};
if (optionalData && !_.isEmpty(optionalData)) {
actionData.headers['Content-Type'] = 'application/json';
actionData.body = JSON.stringify(optionalData);
}
return {
[CALL_API]: actionData
};
}