Skip to content

Instantly share code, notes, and snippets.

@splincode
Created February 15, 2019 22:29
Show Gist options
  • Save splincode/d5766c824d33e66c041ce657e2b57c63 to your computer and use it in GitHub Desktop.
Save splincode/d5766c824d33e66c041ce657e2b57c63 to your computer and use it in GitHub Desktop.
@Injectable({
providedIn: 'root'
})
export class HeroesService {
@Select(HeroesState)
public data$: Observable<Hero[]>;
constructor(
private api: ApiService,
private spinner: NgxSpinnerService
) { }
@Dispatch()
public addHero(name: string, saying: string) {
return new AddHero({ id: AddHero.generateId(), name, saying });
}
@Dispatch()
public deleteHero(id: string) {
return new DeleteHero(id);
}
@Dispatch()
public loadAll = () => {
this.spinner.show();
return this.api.getHeroes().pipe(
map((heroes) => new AddHeroes(heroes)),
finalize(() => this.spinner.hide())
)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment