This is my related code:
private searchClickSubject:Subject<void>; // Submit form
private searchClick$:Observable<any>;
private metrics$:Observable<MetricGroup>;
constructor() {
// Prepare observers
this.searchClickSubject = new Subject<void>();
this.searchClick$ = this.searchClickSubject.asObservable();
}
public ngOnInit() {
// Grab search button click event
this.searchQuery$ = this.searchClick$.pipe(
map(() => <Query>{
offset: 0,
limit: AmetriquesComponent.DEFAULT_PAGE_SIZE
})
);
const loading = () => tap(() => this.loadingPage());
const getAggregatedMetrics = () => switchMap((query: Query) => this.service.getAggregatedMetrics(query));
const loaded = () => tap((aggregatedMetrics: MetricGroup) => this.loadedMetric(aggregatedMetrics));
this.metrics$ = this.searchQuery$
.pipe(
loading(),
getAggregatedMetrics(),
loaded(),
share()
);
}
First of all, I think searchClick$ Observable is hot, since form is generating on submit events regardless of any subscription is attached on.
As you can see, after an "submit" event is emitted, I make an http request. So for each "submit form" emitted a new http request is emitted.
When I attach a subscription on that last Observable, a separate http request is made, so it sounds like first Observable has turned on a cold Observable.
What do you think about my train of thoughs?