瀏覽代碼

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

Richard Knight 6 年之前
父節點
當前提交
4fe49dfbe3
共有 1 個文件被更改,包括 3 次插入1 次删除
  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);