Explorar o código

Improving comments

Richard Knight %!s(int64=6) %!d(string=hai) anos
pai
achega
fbe6e1da1d

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

@@ -34,23 +34,21 @@ export class AppComponent implements OnInit, OnChanges {
 
 	ngOnInit() {
 
-		// Supply the test to run in the query string ?test=3
+		// Optionally supply the test to run in the query string e.g. ?test=3
 		const testcase = parseInt(new URLSearchParams(document.location.search).get('test'), 10) || 2;
 		const { model, meta } = testdata[testcase - 1];
 
-		const hRed = this.hCssRed;
-		const hGreen = this.hCssGreen;
-
-		console.log('%c *** TEST DATA *** ', hRed);
+		console.log('%c *** TEST DATA *** ', this.hCssRed);
 		console.log('Model', model);
 		console.log('Meta', meta);
 
+		// Build the FormGroup and Modeled Metadata from the imported test data
 		const dynaformdata = this.dynaform.build(model, meta);
-
 		({ form: this.form, meta: this.meta } = dynaformdata);
-		console.log('%c *** Modeled MetaData *** ', hGreen);
+
+		console.log('%c *** Modeled MetaData *** ', this.hCssGreen);
 		console.dir(this.meta);
-		console.log('%c *** FormGroup *** ', hGreen);
+		console.log('%c *** FormGroup *** ', this.hCssGreen);
 		console.dir(this.form);
 	}
 

+ 52 - 34
src/app/dynaform/services/dynaform.service.ts

@@ -1,37 +1,55 @@
-/*
-
-Dynaform Service, exposing 8 public methods
-===========================================
-
-build(model, meta) - takes a model and (lazy)metadata and returns an object { form: FormGroup, meta: ModeledMetaData }
-autoBuildFormGroupAndMeta(model, meta) - synonym for build
-autoBuildModeledMeta(model, meta) - takes a model and (lazy)metadata and returns expanded metadata
-
-buildFormGroup(metadata) - builds FormGroups from modelled metdata, recursively if necessary
-buildFieldSpecificMeta(metadata) - use field metadta models to fill out metadata
-combineModelWithMeta(model, extraMeta) - automatically generated metadata for model then combines extra metadata
-combineExtraMeta(metadata, extraMeta) - combine extra metadata into metatdata, lazyly and recursively
-autoMeta(model) - generate basic metadata from a raw or mapped model, recursively if necessary
-
-
-NOTES
------
-This class acts as an injectable wraper around the exports of meta-utils.ts,
-as well as creating a buildFormGroup function using the injected FormBuilder singleton
-
-
-USAGE
------
-
-TO ADD ...
-
-
-EXAMPLES
---------
-
-TO ADD ...
-
-*/
+/* ***************************************************************************************************************************************
+ * Dynaform Service, exposing 8 public methods
+ * ***************************************************************************************************************************************
+ *
+ * build(model, meta = {}, createFromMeta = false)
+ *
+ * Takes a model and (lazy)metadata and returns an object containing a FormGroup and Modeled MetaData :
+ * {
+ *     form: FormGroup,
+ *     meta: ModeledMetaData
+ * }
+ *
+ * meta is optional, and if not supplied all the model fields will become Text inputs in the FormGroup,
+ * with their labels set to the un-camel-cased property name
+ *
+ * createFromMeta is optional. If true it will create new fields in the FormGroup when they don't already exist in the model.
+ * If defaults to false, except when a completly empty model {} is supplied.
+ *
+ * USAGE
+ * -----
+ *
+ * build(model)
+ * build({}, meta)
+ * build(model, meta)
+ * build(model, meta, true)
+ *
+ *
+ * LOWER-LEVEL METHODS
+ * -------------------
+ *
+ * autoBuildFormGroupAndMeta(model, meta, createFromMeta) - synonym for build
+ * autoBuildModeledMeta(model, meta, createFromMeta) - takes a model and (lazy)metadata and returns expanded metadata
+ *
+ * buildFormGroup(metadata) - builds FormGroups from modelled metdata, recursively if necessary
+ * buildFieldSpecificMeta(metadata) - use field metadta models to fill out metadata
+ * combineModelWithMeta(model, extraMeta) - automatically generated metadata for model then combines extra metadata
+ * combineExtraMeta(metadata, extraMeta) - combine extra metadata into metatdata, lazyly and recursively
+ * autoMeta(model) - generate basic metadata from a raw or mapped model, recursively if necessary
+ *
+ *
+ * NOTES
+ * -----
+ * This class acts as an injectable wraper around the exports of meta-utils.ts,
+ * as well as creating a buildFormGroup function using the injected FormBuilder singleton
+ *
+ *
+ * EXAMPLES
+ * --------
+ *
+ * TO ADD ...
+ *
+ */
 
 import { Injectable } from '@angular/core';
 import { FormBuilder, FormGroup } from '@angular/forms';

+ 0 - 2
src/app/dynaform/services/meta-utils.ts

@@ -132,10 +132,8 @@ const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup =>
 	const buildFormGroup = metaG => {
 		// Ensure that we have Field-Specific Metadata, not raw Objects
 		const metaWithNameKeys = addMissingNames(metaG);
-		console.log(metaWithNameKeys);
 		// MAYBE only run this if first entry isn't right, for reasons of efficiency
 		const fieldModeledMeta = addMissingFieldSpecificMeta(metaWithNameKeys);
-		console.log(fieldModeledMeta);
 		return _buildFormGroup(fieldModeledMeta);
 	};
 	return buildFormGroup;