I recently find myself more and more getting into the habits of defining my side-effects in dedicated private methods that name the sort of side-effect for what it does.
That is very intentional to decouple each aspect of some sort of components behaviour from one another.
That leads to something like this (Uses ReactiveForms, so syncing external data into the form or changing somethin in field A based on something in field B happens via side-effects):
export class DirectDebitForm {
... bunch of injections ...
... bunch of fields ...
directDebitForm = new FormGroup({
... the fields ...
})
constructor(){
this.setupSetIbanAsInvalidOnInvalidBackendValidation();
this.setupBackendIbanValidationOnIbanChange();
this.setupNavigateOnSuccessfulRequest();
this.setupSyncPaymentDataFromSelectedProductToForm();
}
public submitRequest(){...}
private setupSetIbanAsInvalidOnInvalidBackendValidation(){...}
private setupBackendIbanValidationOnIbanChange(){...}
private setupNavigateOnSuccessfulRequest(){...}
private setupSyncPaymentDataFromSelectedProductToForm(){...}
}
Any of these private functions basically is either a effect(() => {}) or pipe(takeUntilDestroyed()).subscribe(() => {}) call.
I kind of like how it strictly disentangles my side-effects, though some of them do interact with one another which I tend to mark with doc comments.
Any thoughts or opinions on that style? Suggestions?