Created
September 20, 2022 12:28
-
-
Save e-oz/719de211093cf76cb5cd87d8d0b3d36a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Not so perfect | |
export class RegStore extends ComponentStore<SomeState> { | |
private readonly registrationSuccess$ = this.effect(_ => _.pipe( | |
tap(() => { | |
this.patchState({success: true}); | |
this.regsCounterAdd$(); | |
}) | |
)); | |
private readonly regsCounterAdd$ = this.effect(_ => _.pipe( | |
siwtchMap(() => this.regSrv.increaseCounter()) | |
)); | |
constructor(private readonly regSrv: RegService) { | |
super({}); | |
} | |
} | |
// Better | |
export class RegStore extends ComponentStore<SomeState> { | |
private readonly registrationSuccess$ = this.effect(_ => _.pipe( | |
switchMap(() => { | |
this.patchState({success: true}); | |
return this.regCounterRequest(); | |
}) | |
)); | |
private regCounterRequest(): Observable<unknown> { | |
return this.regSrv.increaseCounter(); | |
} | |
constructor(private readonly regSrv: RegService) { | |
super({}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment