drnaf
Version:
Dynamic React-Native Application Framework
52 lines (39 loc) • 1.21 kB
JavaScript
import { l } from "../utilities/Logs";
const ct = 'AsAPI->';
function asAPI(track = {
from: '-',
}, action, dataCollection) {
// prepare usage variables
const mtn = ct + "asAPI(" + track.from + ")"
const props = action.props;
// is props ready
if (nonNullNonUndefined(props)) {
// merge fields
mergeFields(props.attach_fields, dataCollection);
} else l.e(mtn +"props is not ready.");
}
/** Feature methods */
function mergeFields(attachFields, dataCollection) {
// prepare usage variables
const fields = doesAttachFieldReady(attachFields);
const keyNames = Object.keys(fields);
const keyLength = keyNames.length;
for (var a = 0; a < keyLength; a++) {
// prepare usage variables
const keyName = keyNames[a];
// merge field
dataCollection[keyName + ""] = attachFields[keyName + ""];
}
}
/** Micro methods */
function nonNullNonUndefined(obj) {
return (obj !== null && obj !== undefined);
}
function doesAttachFieldReady(attachFields) {
if (nonNullNonUndefined(attachFields)
&& typeof attachFields === 'object') {
return attachFields;
}
return {};
}
export { asAPI }