Skip to content

Commit

Permalink
fix(lib): deprecate OnFormUpdate hook
Browse files Browse the repository at this point in the history
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 #127

And I've given more details here: #86 (comment)
  • Loading branch information
maxime1992 committed Jan 8, 2020
1 parent 050cd3a commit aa3c9a7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export class CrewMemberComponent extends NgxSubFormComponent<CrewMember> {

**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<FormInterface>): 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<FormInterface>): 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)
Expand Down
2 changes: 2 additions & 0 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormInterface> {
// @deprecated
onFormUpdate?: (formUpdate: FormUpdate<FormInterface>) => void;
}

Expand Down

0 comments on commit aa3c9a7

Please sign in to comment.