Skip to content

Commit

Permalink
feat: implement missing handleEmissionRate
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime1992 committed Nov 21, 2021
1 parent 908e4b7 commit 45391e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 13 additions & 4 deletions projects/ngx-sub-form/new/src/ngx-sub-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export function createForm<ControlInterface, FormInterface>(
if (!isRoot<ControlInterface, FormInterface>(options)) {
return formGroup.valueChanges.pipe(delay(0));
} else {
// @todo following could probably be refactored a bit to avoid code duplication
if (options.manualSave$) {
return options.manualSave$.pipe(
withLatestFrom(formGroup.valueChanges),
Expand All @@ -168,10 +169,18 @@ export function createForm<ControlInterface, FormInterface>(
filter(formValue => formGroup.valid && !isEqual(transformedValue, formValue)),
);
} else {
return formGroup.valueChanges.pipe(
delay(0),
filter(formValue => formGroup.valid && !isEqual(transformedValue, formValue)),
);
if (options.handleEmissionRate) {
return formGroup.valueChanges.pipe(
options.handleEmissionRate,
delay(0),
filter(formValue => formGroup.valid && !isEqual(transformedValue, formValue)),
);
} else {
return formGroup.valueChanges.pipe(
delay(0),
filter(formValue => formGroup.valid && !isEqual(transformedValue, formValue)),
);
}
}
}
}),
Expand Down
3 changes: 3 additions & 0 deletions projects/ngx-sub-form/new/src/ngx-sub-form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export type NgxRootFormOptions<ControlInterface, FormInterface = ControlInterfac
// if you want to transform it into a manual root form, provide the
// following observable which trigger a save every time a value is emitted
manualSave$?: Observable<void>;
// @todo it should either be `manualSave$` OR `handleEmissionRate` OR none of them
// if you're creating an automatic root form, you can customise the emission rate
handleEmissionRate?: (obs$: Observable<FormInterface>) => Observable<FormInterface>;
};

export enum FormType {
Expand Down

0 comments on commit 45391e3

Please sign in to comment.