Browse Source

Added isRealObject helper function, as typeof null === 'object' in plain js

Richard Knight 6 years ago
parent
commit
4fe49dfbe3
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/app/dynaform/services/_formdata-utils.ts

+ 3 - 1
src/app/dynaform/services/_formdata-utils.ts

@@ -457,13 +457,15 @@ const execMetaReorderingInstructions = (metaG: StringMap<any>) => {
 // (used to produce an updated copy of a model when form values are changed - will not create new keys)
 // ---------------------------------------------------------------------------------------------------------------------
 
+const isRealObject = val => val !== null && typeof val === 'object'; // js quirk - typeof null ---> 'object'
+
 const generateNewModel = (originalModel, updates) => {
 	return updateObject(originalModel, updates);
 };
 
 const updateObject = (obj, updates, createAdditionalKeys = false) => {
 	// THIS DOES NOT MUTATE obj, instead returning a new object
-	if (typeof obj !== 'object') {
+	if (!isRealObject(obj)) {
 		obj = {};
 	}
 	console.log('obj is', obj, typeof obj);