|
@@ -7,7 +7,6 @@ import { reduce } from 'lodash/fp';
|
|
|
* Exports
|
|
|
* -------
|
|
|
* buildFormGroup(metadata) - builds FormGroups from metdata, recursively if necessary
|
|
|
- * addMissingNames(metadata) - adds any missing 'name' properties to Fields and Groups using property's key, recursively
|
|
|
*
|
|
|
* Variable names
|
|
|
* --------------
|
|
@@ -24,7 +23,7 @@ const addProp = (obj, key, val) => { obj[key] = val; return obj; };
|
|
|
// Helper function to distinguish group from field
|
|
|
const isGroup = metaFoG => metaFoG.meta && !metaFoG._field;
|
|
|
|
|
|
-// Add names to both Fields and Groups if missing, using property's key
|
|
|
+// Adds any missing 'name' properties to Fields and Groups using property's key, recursively
|
|
|
const addNameIfMissing = (metaFoG, key) => metaFoG.name ? metaFoG : addProp(metaFoG, 'name', key);
|
|
|
const addNameToSelfAndChildren = ( [key, metaFoG] ) => {
|
|
|
metaFoG = addNameIfMissing(metaFoG, key);
|
|
@@ -35,7 +34,7 @@ const addNameToSelfAndChildren = ( [key, metaFoG] ) => {
|
|
|
};
|
|
|
const addMissingNames = metaG => Object.entries(metaG)
|
|
|
.map(addNameToSelfAndChildren)
|
|
|
- .reduce((res, [key, val]) => { res[key] = val; return res; }, {});
|
|
|
+ .reduce((res, [key, val]) => addProp(res, key, val), {});
|
|
|
|
|
|
// Build Form Control
|
|
|
// TODO: Flesh out function to build validators
|
|
@@ -48,13 +47,14 @@ const buildValidators = metaF => ({
|
|
|
const buildFormControl = metaF => new FormControl(buildControlState(metaF) /*, buildValidators(metaF) */);
|
|
|
|
|
|
// Build Form Group Member
|
|
|
-const buildFormGroupMember = metaFoG => isGroup(metaFoG) ? buildFormGroup(metaFoG.meta) : buildFormControl(metaFoG);
|
|
|
+const buildFormGroupMember = metaFoG => isGroup(metaFoG) ? _buildFormGroup(metaFoG.meta) : buildFormControl(metaFoG);
|
|
|
|
|
|
// Build Form Group
|
|
|
const buildFormGroupReducerIteree = (res, metaFoG) => Object.assign(res, { [metaFoG.name]: buildFormGroupMember(metaFoG) });
|
|
|
-const buildFormGroup = metaG => fb.group(reduce(buildFormGroupReducerIteree, {}, metaG));
|
|
|
+const _buildFormGroup = metaG => fb.group(reduce(buildFormGroupReducerIteree, {}, metaG));
|
|
|
+const buildFormGroup = metaG => _buildFormGroup(addMissingNames(metaG));
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// Exports
|
|
|
|
|
|
-export { addMissingNames, buildFormGroup };
|
|
|
+export { buildFormGroup };
|