Explorar o código

Debugging it all"

Richard Knight %!s(int64=6) %!d(string=hai) anos
pai
achega
c494421442
Modificáronse 2 ficheiros con 9 adicións e 8 borrados
  1. 5 6
      src/app/app.component.ts
  2. 4 2
      src/app/dynaform/libs/index.ts

+ 5 - 6
src/app/app.component.ts

@@ -24,12 +24,11 @@ export class AppComponent implements OnInit {
 	}
 
 	ngOnInit() {
-		const test = {a: {prop: 1}, b: {prop: 2}};
-		console.log( addMissingNames(test) );
-		// console.log( addMissingNames(this.formMetaDataObj) );
-		const fg = buildFormGroup({
-			dynaformtest: { name: 'dynaformtest', meta: this.formMetaDataObj }
-		});
+		const fullFormMeta = {
+			dynaformtest: { meta: this.formMetaDataObj }
+		};
+		const withNamesAdded = addMissingNames(fullFormMeta);
+		const fg = buildFormGroup(withNamesAdded);
 		console.log(fg);
 		this.form = fg;
 	}

+ 4 - 2
src/app/dynaform/libs/index.ts

@@ -19,15 +19,17 @@ import { reduce } from 'lodash/fp';
 
 const fb = new FormBuilder();
 
+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
-const addNameIfMissing = (metaFoG, key) => metaFoG.name ? metaFoG : Object.assign(metaFoG, { name: key });
+const addNameIfMissing = (metaFoG, key) => metaFoG.name ? metaFoG : addProp(metaFoG, 'name', key);
 const addNameToSelfAndChildren = ( [key, metaFoG] ) => {
 	metaFoG = addNameIfMissing(metaFoG, key);
 	if (isGroup(metaFoG)) {
-		metaFoG = addMissingNames(metaFoG.meta); // Recursion
+		metaFoG.meta = addMissingNames(metaFoG.meta); // Recursion
 	}
 	return [key, metaFoG];
 };