chore(hierarchical-dependency-injection): Subscriber -> Observer (#3097)
This commit is contained in:
parent
8811094954
commit
adec6ac6ce
|
@ -1,7 +1,7 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { Subscriber } from 'rxjs/Subscriber';
|
import { Observer } from 'rxjs/Observer';
|
||||||
|
|
||||||
import { Hero, HeroTaxReturn } from './hero';
|
import { Hero, HeroTaxReturn } from './hero';
|
||||||
|
|
||||||
|
@ -18,30 +18,30 @@ export class HeroesService {
|
||||||
];
|
];
|
||||||
|
|
||||||
getHeroes(): Observable<Hero[]> {
|
getHeroes(): Observable<Hero[]> {
|
||||||
return new Observable<Hero[]>((subscriber: Subscriber<Hero[]>) => {
|
return new Observable<Hero[]>((observer: Observer<Hero[]>) => {
|
||||||
subscriber.next(this.heroes);
|
observer.next(this.heroes);
|
||||||
subscriber.complete();
|
observer.complete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getTaxReturn(hero: Hero): Observable<HeroTaxReturn> {
|
getTaxReturn(hero: Hero): Observable<HeroTaxReturn> {
|
||||||
return new Observable<HeroTaxReturn>((subscriber: Subscriber<HeroTaxReturn>) => {
|
return new Observable<HeroTaxReturn>((observer: Observer<HeroTaxReturn>) => {
|
||||||
const htr = this.heroTaxReturns.find(t => t.hero.id === hero.id);
|
const htr = this.heroTaxReturns.find(t => t.hero.id === hero.id);
|
||||||
subscriber.next(htr || new HeroTaxReturn(0, hero));
|
observer.next(htr || new HeroTaxReturn(0, hero));
|
||||||
subscriber.complete();
|
observer.complete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTaxReturn(heroTaxReturn: HeroTaxReturn): Observable<HeroTaxReturn> {
|
saveTaxReturn(heroTaxReturn: HeroTaxReturn): Observable<HeroTaxReturn> {
|
||||||
return new Observable<HeroTaxReturn>((subscriber: Subscriber<HeroTaxReturn>) => {
|
return new Observable<HeroTaxReturn>((observer: Observer<HeroTaxReturn>) => {
|
||||||
const htr = this.heroTaxReturns.find(t => t.id === heroTaxReturn.id);
|
const htr = this.heroTaxReturns.find(t => t.id === heroTaxReturn.id);
|
||||||
if (htr) {
|
if (htr) {
|
||||||
heroTaxReturn = Object.assign(htr, heroTaxReturn); // demo: mutate
|
heroTaxReturn = Object.assign(htr, heroTaxReturn); // demo: mutate
|
||||||
} else {
|
} else {
|
||||||
this.heroTaxReturns.push(heroTaxReturn);
|
this.heroTaxReturns.push(heroTaxReturn);
|
||||||
}
|
}
|
||||||
subscriber.next(heroTaxReturn);
|
observer.next(heroTaxReturn);
|
||||||
subscriber.complete();
|
observer.complete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue