Skip to content

Instantly share code, notes, and snippets.

@msarsha
Created July 3, 2020 10:39
Show Gist options
  • Save msarsha/2865ff13d1aeda1d1501c81e1f2cac36 to your computer and use it in GitHub Desktop.
Save msarsha/2865ff13d1aeda1d1501c81e1f2cac36 to your computer and use it in GitHub Desktop.
getRate() {
this.items$ = this.service.getConversion()
.pipe(
tap((data) => {this.conversionRate = data.rates.USD;}),
switchMap(() => this.createItemsObservable())
)
}
private createItemsObservable(): Observable<Item[]>{
return this.itemsQuery.selectAll()
.pipe(
map(itmes => itmes.filter(item=> {return !item.received;})),
map(res => res.sort((item1, item2) =>
{ return (item1.deliveryDate > item2.deliveryDate ? 1 : -1) }))
);
}
// then you can also make your ngOnInit shorter
ngOnInit() {
this.items$ = this.createItemsObservable();
const source = interval(10000);
this.subscription = source.subscribe(val => this.getRate());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment