From 5d6fc93f53adc787f132a227b87fbb7225db3a69 Mon Sep 17 00:00:00 2001 From: dimas Date: Sat, 22 Jan 2022 23:24:27 +0700 Subject: [PATCH 1/2] fix clone initialValues --- lib/util.js | 3 ++- package-lock.json | 11 +++++++++++ package.json | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 98d99c5..ba1abd7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,4 +1,5 @@ import {dequal as isEqual} from 'dequal/lite'; +import structuredClone from '@ungap/structured-clone' function subscribeOnce(observable) { return new Promise((resolve) => { @@ -14,7 +15,7 @@ function update(object, path, value) { } function cloneDeep(object) { - return JSON.parse(JSON.stringify(object)); + return structuredClone(object) } function isNullish(value) { diff --git a/package-lock.json b/package-lock.json index e487d9c..e3b648a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0-semantically-released", "license": "MIT", "dependencies": { + "@ungap/structured-clone": "^0.3.4", "dequal": "^2.0.2" }, "devDependencies": { @@ -3928,6 +3929,11 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@ungap/structured-clone": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-0.3.4.tgz", + "integrity": "sha512-TSVh8CpnwNAsPC5wXcIyh92Bv1gq6E9cNDeeLu7Z4h8V4/qWtXJp7y42qljRkqcpmsve1iozwv1wr+3BNdILCg==" + }, "node_modules/abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -22149,6 +22155,11 @@ "eslint-visitor-keys": "^3.0.0" } }, + "@ungap/structured-clone": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-0.3.4.tgz", + "integrity": "sha512-TSVh8CpnwNAsPC5wXcIyh92Bv1gq6E9cNDeeLu7Z4h8V4/qWtXJp7y42qljRkqcpmsve1iozwv1wr+3BNdILCg==" + }, "abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", diff --git a/package.json b/package.json index ffbeb56..a5b1fdc 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "module": "./build/index.mjs", "license": "MIT", "dependencies": { + "@ungap/structured-clone": "^0.3.4", "dequal": "^2.0.2" }, "devDependencies": { From b7221adf5044813a247ae26b8fb0c3d096503466 Mon Sep 17 00:00:00 2001 From: dimas Date: Sat, 22 Jan 2022 23:44:08 +0700 Subject: [PATCH 2/2] [test] initialValues should same value as $form --- test/specs/library.spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/specs/library.spec.js b/test/specs/library.spec.js index dd05998..3a93385 100644 --- a/test/specs/library.spec.js +++ b/test/specs/library.spec.js @@ -22,6 +22,7 @@ describe('createForm', () => { name: chance.name(), email: chance.email(), country: chance.country(), + date: chance.date(), }; let validationSchema = yup.object().shape({ name: yup.string().required(), @@ -63,6 +64,12 @@ describe('createForm', () => { expect(values.country).toBe(initialValues.country); }); }); + + it('returns an exact initialValues', () => { + subscribeOnce(instance.form).then((values) => { + expect(values.date).toStrictEqual(initialValues.date); + }) + }) }); describe('$errors', () => {