Repository: jaredpalmer/formik
Pull request #1423 (2019-04-09 09:01:51)

Updating documentation of submitForm
Hello,

A little first PR :)

Updating documentions according to #486.

Have a nice day


Patch:
diff --git a/.storybook/webpack.config.js b/.storybook/webpack.config.js
index 8e8ff78..2f8248f 100644
--- a/.storybook/webpack.config.js
+++ b/.storybook/webpack.config.js
@@ -1,23 +1,15 @@
-const TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
+const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
 
 module.exports = (storybookBaseConfig, configType, defaultConfig) => {
-
-
-  defaultConfig.module.rules.push(
-    {
-      test: /\.tsx?$/,
-      exclude: /node_modules/,
-      loader: 'awesome-typescript-loader',
+  defaultConfig.module.rules.push({
+    test: /\.tsx?$/,
+    loader: 'awesome-typescript-loader',
+    options: {
+      configFileName: 'tsconfig.storybook.json',
     },
-  )
-  defaultConfig.resolve.extensions = ['.ts', '.tsx', '.js', '.jsx']
-  defaultConfig.resolve.plugins = [
-    new TsConfigPathsPlugin({
-      tsconfig: 'tsconfig.json',
-      compiler: 'typescript'
-    })
-  ]
-
-  return defaultConfig
+  });
+  defaultConfig.resolve.extensions = ['.ts', '.tsx', '.js', '.jsx'];
+  defaultConfig.resolve.plugins = [new TsConfigPathsPlugin({})];
 
-}
\ No newline at end of file
+  return defaultConfig;
+};
diff --git a/docs/api/fastfield.md b/docs/api/fastfield.md
index 9ca395f..c0de312 100644
--- a/docs/api/fastfield.md
+++ b/docs/api/fastfield.md
@@ -6,7 +6,7 @@ custom_edit_url: https://github.com/jaredpalmer/formik/edit/master/docs/api/fast
 
 ## Before we start
 
-`<FastField />` is meant for performance _optimization_. However, you really do not need to use it until you do. Only proceed if you are familiar with how React's [`shouldComponentUpdate()`](https://reactjs.org/docs/react-component.html#shouldcomponentupdate) works. You have been warned.\*\*
+`<FastField />` is meant for performance _optimization_. However, you really do not need to use it until you do. Only proceed if you are familiar with how React's [`shouldComponentUpdate()`](https://reactjs.org/docs/react-component.html#shouldcomponentupdate) works. You have been warned.
 
 **No. Seriously. Please review the following parts of the official React documentation before continuing**
 
diff --git a/docs/api/formik.md b/docs/api/formik.md
index c7659aa..7ec8736 100644
--- a/docs/api/formik.md
+++ b/docs/api/formik.md
@@ -131,9 +131,9 @@ Set the error message of a field imperatively. `field` should match the key of
 Set the touched state of a field imperatively. `field` should match the key of
 `touched` you wish to update. Useful for creating custom input blur handlers. Calling this method will trigger validation to run if `validateOnBlur` is set to `true` (which it is by default). `isTouched` defaults to `true` if not specified. You can also explicitly prevent/skip validation by passing a third argument as `false`.
 
-#### `submitForm: () => void`
+#### `submitForm: () => Promise`
 
-Trigger a form submission.
+Trigger a form submission. The promise will be rejected if form is invalid. 
 
 #### `submitCount: number`
 
diff --git a/src/utils.ts b/src/utils.ts
index 8c7bb10..b09c3d7 100755
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -23,7 +23,7 @@ export function getIn(
  * @see https://github.com/developit/linkstate
  */
 export function setIn(obj: any, path: string, value: any): any {
-  let res: any = {};
+  let res: any = cloneDeep(obj);
   let resVal: any = res;
   let i = 0;
   let pathArray = toPath(path);
@@ -54,15 +54,13 @@ export function setIn(obj: any, path: string, value: any): any {
     resVal[pathArray[i]] = value;
   }
 
-  const result = { ...obj, ...res };
-
   // If the path array has a single element, the loop did not run.
   // Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.
   if (i === 0 && value === undefined) {
-    delete result[pathArray[i]];
+    delete res[pathArray[i]];
   }
 
-  return result;
+  return res;
 }
 
 /**
diff --git a/tsconfig.storybook.json b/tsconfig.storybook.json
new file mode 100644
index 0000000..413528f
--- /dev/null
+++ b/tsconfig.storybook.json
@@ -0,0 +1,7 @@
+{
+  "extends": "./tsconfig.base.json",
+  "include": ["src", "./typings.d.ts", "types"],
+  "compilerOptions": {
+    "baseUrl": "./"
+  }
+}
\ No newline at end of file


Test patch:
diff --git a/test/utils.test.tsx b/test/utils.test.tsx
index 820eeac..811b022 100755
--- a/test/utils.test.tsx
+++ b/test/utils.test.tsx
@@ -235,6 +235,21 @@ describe('utils', () => {
       expect(obj).toEqual({ x: 'y' });
       expect(newObj).toEqual({ x: 'y', a: { x: { c: 'value' } } });
     });
+
+    it('should keep class inheritance for the top level object', () => {
+      class TestClass {
+        constructor(public key: string, public setObj?: any) {}
+      }
+      const obj = new TestClass('value');
+      const newObj = setIn(obj, 'setObj.nested', 'setInValue');
+      expect(obj).toEqual(new TestClass('value'));
+      expect(newObj).toEqual({
+        key: 'value',
+        setObj: { nested: 'setInValue' },
+      });
+      expect(obj instanceof TestClass).toEqual(true);
+      expect(newObj instanceof TestClass).toEqual(true);
+    });
   });
 
   describe('isPromise', () => {