Skip to content

Instantly share code, notes, and snippets.

@RusEu
Created May 5, 2019 18:22
Show Gist options
  • Save RusEu/4d09b346c88b3ba426a88866184931f3 to your computer and use it in GitHub Desktop.
Save RusEu/4d09b346c88b3ba426a88866184931f3 to your computer and use it in GitHub Desktop.
import { Subject } from 'rxjs/Rx';
import { OnDestroy } from '@angular/core';
export abstract class UnsubscribeOnDestroy implements OnDestroy {
protected d$: Subject<any>;
constructor() {
this.d$ = new Subject<void>();
const f = this.ngOnDestroy;
this.ngOnDestroy = () => {
f();
this.d$.next();
this.d$.complete();
};
}
public ngOnDestroy() {
// no-op
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment