Skip to content

Commit

Permalink
fix: default form value not cloned as original object type
Browse files Browse the repository at this point in the history
  • Loading branch information
anschm committed Aug 2, 2022
1 parent 200d681 commit bfc92fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/uuid": "8.3.4",
"commitizen": "4.2.4",
"core-js": "3.23.1",
"lodash-es": "4.17.21",
"fast-deep-equal": "3.1.3",
"ngx-observable-lifecycle": "2.2.1",
"rxjs": "7.5.5",
Expand All @@ -70,6 +71,7 @@
"@types/jasmine": "4.0.3",
"@types/jasminewd2": "2.0.10",
"@types/node": "17.0.40",
"@types/lodash": "4.14.182",
"@typescript-eslint/eslint-plugin": "5.28.0",
"@typescript-eslint/parser": "5.28.0",
"cypress": "10.1.0",
Expand Down
5 changes: 2 additions & 3 deletions projects/ngx-sub-form/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
OneOfControlsTypes,
TypedFormGroup,
} from './shared/ngx-sub-form-utils';

export const deepCopy = <T>(value: T): T => JSON.parse(JSON.stringify(value));
import { cloneDeep } from 'lodash';

/** @internal */
export const patchClassInstance = (componentInstance: any, obj: Object) => {
Expand Down Expand Up @@ -122,7 +121,7 @@ export function createFormDataFromOptions<ControlInterface, FormInterface>(
options.formControls,
options.formGroupOptions as AbstractControlOptions,
) as TypedFormGroup<FormInterface>;
const defaultValues: FormInterface = deepCopy(formGroup.value);
const defaultValues: FormInterface = cloneDeep(formGroup.value);
const formGroupKeys: (keyof FormInterface)[] = Object.keys(defaultValues) as (keyof FormInterface)[];
const formControlNames: ControlsNames<FormInterface> = formGroupKeys.reduce<ControlsNames<FormInterface>>(
(acc, curr) => {
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,11 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==

"@types/lodash@4.14.182":
version "4.14.182"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==

"@types/mime@^1":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
Expand Down Expand Up @@ -6901,6 +6906,11 @@ locate-path@^5.0.0:
dependencies:
p-locate "^4.1.0"

lodash-es@4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash.capitalize@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz#f826c9b4e2a8511d84e3aca29db05e1a4f3b72a9"
Expand Down

0 comments on commit bfc92fb

Please sign in to comment.