Skip to content

Instantly share code, notes, and snippets.

@e-oz
Created September 20, 2022 12:28
Show Gist options
  • Save e-oz/719de211093cf76cb5cd87d8d0b3d36a to your computer and use it in GitHub Desktop.
Save e-oz/719de211093cf76cb5cd87d8d0b3d36a to your computer and use it in GitHub Desktop.
// 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