For some reason, I am facing an issue where when I use Observable along with an extension method and pipe in my code, the map or tap function within the pipe is not getting triggered.
import { Observable, Subscriber, Observer } from 'rxjs';
import { tap, map } from 'rxjs/operators';
...
declare module 'rxjs' {
interface Observable<T> {
useCache<T>(this: Observable<T>, key: string): Observable<T>;
}
}
Observable.prototype.useCache = function<T>(this: Observable<T>, key: string) {
// executed
const inCache = LocalStorage.get(key);
if (inCache) {
return new Observable<T>(observer => observer.next(inCache));
}
// this.pipe(tap((e: T) => {
// LocalStorage.set(key, e);
// }));
this.pipe(map((e: T) => {
//not executed
LocalStorage.set(key, e);
}));
return this;
};
...
(in somewhere component)
this.service.get(...).subscribe(e=>{
//executed!
});
In various other parts of my code, I can set breakpoints that work correctly except inside the map lambda function.