drnaf
Version:
Dynamic React-Native Application Framework
69 lines (55 loc) • 1.59 kB
JavaScript
/** Instance variables */
import { post } from '../networks/Fire';
import { l } from '../utilities/Logs';
import { ActionTypes } from '../constants/ActionTypes';
import { asAPI } from './AsAPI';
/** Explicit variables */
const ct = 'Actions->';
function doIt(params = {
dataCollection: {},
action: {
type: null,
props: {
url: null,
method: null,
params: null,
map_fields_to_params: null,
}
},
callback: null,
}, track) {
// prepare usage variables
const mtn = ct + "actions() ";
// try {
// prepare usage variables
const action = params.action;
// type condition
if (action.type === ActionTypes.API.NAME) {
// prepare prop as API
asAPI(track, action, params.dataCollection);
// apis
apis(params, params.dataCollection);
} else l.e(mtn + "action type[" + action.type + "] does not matches.");
// } catch (e) {
// l.e(mtn + "err: " + e.message);
// }
}
/** Feature methods */
function apis(params, requestBody) {
// prepare usage variables
const mtn = ct + "apis() ";
//--> props
const action = params.action;
const props = action.props;
const url = props.url;
const method = props.method;
if (method === 'post') {
post(url, requestBody, {
callback: (val) => {
// callbacks
params.callback(val);
}
})
} else l.e(mtn + "method[" + method + "] does not matched.");
}
export default { doIt }