From aa3c9a7b8b6838d3b60b77d96dbd60595249a031 Mon Sep 17 00:00:00 2001 From: Maxime ROBERT Date: Wed, 8 Jan 2020 18:22:28 +0000 Subject: [PATCH] fix(lib): deprecate `OnFormUpdate` hook If you patch your form and update a few values, this hook will be called multiple times: 1 time for each updated value. Which is not ideal. Also has a bug here https://github.com/cloudnc/ngx-sub-form/issues/127 And I've given more details here: https://github.com/cloudnc/ngx-sub-form/issues/86#issuecomment-561758526 --- README.md | 2 +- projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 69ab2bc5..f22c9ec7 100644 --- a/README.md +++ b/README.md @@ -538,7 +538,7 @@ export class CrewMemberComponent extends NgxSubFormComponent { **Hooks** -- `onFormUpdate`: Allows you to react whenever the form is being modified. Instead of subscribing to `this.formGroup.valueChanges` or `this.formControls.someProp.valueChanges` you will not have to deal with anything asynchronous nor have to worry about subscriptions and memory leaks. Just implement the method `onFormUpdate(formUpdate: FormUpdate): void` and if you need to know which property changed do a check like the following: `if (formUpdate.yourProperty) {}`. Be aware that this method will be called only when there are either local changes to the form or changes coming from subforms. If the parent `setValue` or `patchValue` this method won't be triggered +- `onFormUpdate` [**_deprecated_**]: Allows you to react whenever the form is being modified. Instead of subscribing to `this.formGroup.valueChanges` or `this.formControls.someProp.valueChanges` you will not have to deal with anything asynchronous nor have to worry about subscriptions and memory leaks. Just implement the method `onFormUpdate(formUpdate: FormUpdate): void` and if you need to know which property changed do a check like the following: `if (formUpdate.yourProperty) {}`. Be aware that this method will be called only when there are either local changes to the form or changes coming from subforms. If the parent `setValue` or `patchValue` this method won't be triggered - `getFormGroupControlOptions`: Allows you to define control options for construction of the internal FormGroup. Use this to define form-level validators - `createFormArrayControl`: Allows you to create the `FormControl` of a given property of your form (to define validators for example). When you want to use this hook, implement the following interface `NgxFormWithArrayControls` - `handleEmissionRate`: Allows you to define a custom emission rate (top level or any sub level) diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts index 71f4b967..81c7661f 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts @@ -2,7 +2,9 @@ import { FormControl, FormGroup, ValidationErrors } from '@angular/forms'; import { Observable } from 'rxjs'; import { ArrayPropertyKey, ArrayPropertyValue, Controls, FormUpdate } from './ngx-sub-form-utils'; +// @deprecated export interface OnFormUpdate { + // @deprecated onFormUpdate?: (formUpdate: FormUpdate) => void; }