Skip to content

Commit

Permalink
Merge pull request #210 from zakhenry/fix/mistaken-negation
Browse files Browse the repository at this point in the history
Fix/mistaken negation
  • Loading branch information
zak-cloudnc authored Mar 17, 2021
2 parents 412c588 + 9eb8531 commit aaefb64
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function createForm<ControlInterface, FormInterface>(
)
: formGroup.valueChanges;

// it might be surprising to see formGroup.valid being checked twice
// it might be surprising to see formGroup validity being checked twice
// here, however this is intentional. The delay(0) allows any sub form
// components to populate values into the form, and it is possible for
// the form to be invalid after this process. In which case we suppress
Expand All @@ -164,9 +164,17 @@ export function createForm<ControlInterface, FormInterface>(
return formValues$.pipe(
filter(() => formGroup.valid),
delay(0),
filter(
formValue => formGroup.valid && (options.outputFilterPredicate ?? isEqual)(transformedValue, formValue),
),
filter(formValue => {
if (formGroup.invalid) {
return false;
}

if (options.outputFilterPredicate) {
return options.outputFilterPredicate(transformedValue, formValue);
}

return !isEqual(transformedValue, formValue);
}),
options.handleEmissionRate ?? identity,
);
}
Expand Down

0 comments on commit aaefb64

Please sign in to comment.