Move takeUntil rxjs operator to separate method

I have BaseComponent class in my Angular app, which implements destroy$: Subject<void> for observables. Every time I subscribe to service, I'm doing:

this.myService.loadData()
    .pipe(takeUntil(this.destroy$))
    .subscribe(data => this.userData = data);

I want to avoid writing .pipe(takeUntil(this.destroy$)) everywhere and I'm wondering, is there any way to create extension method for observable and handle takeUntil there? for example to move .pipe(takeUntil(this.destroy$)) to my custom method ifAlive and make it look like this:

this.myService.loadData()
    .isAlive()
    .subscribe(...);

Any ideas?



from Recent Questions - Stack Overflow https://ift.tt/2Tnd0Sj
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)