This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, OnDestroy } from "@angular/core"; | |
import { Subject } from "rxjs"; | |
import { takeUntil } from "rxjs/operators"; | |
@Directive() // Needed only for Angular v9+ strict mode that enforce decorator to enable Component inheritance | |
export abstract class BaseComponent implements OnDestroy { | |
// _destroy$ is LAZY: it'll be created (and allocate memory) only if you use takeUntilDestroy | |
private _destroy$?: Subject<void>; | |
protected takeUntilDestroy = <T>() => { | |
if (!this._destroy$) this._destroy$ = new Subject<void>(); // LAZY Subject |