UNPKG

@bespunky/angular-zen

Version:

The Angular tools you always wished were there.

63 lines (62 loc) 3.02 kB
import { Observable, PartialObserver, Subject, Subscription } from 'rxjs'; import { OnDestroy } from '@angular/core'; import * as i0 from "@angular/core"; /** * Facilitates working with components, directives and services which manually subscribe to observables. * Extend this class to easily hook into ngOnDestroy and avoid memory leaks. * * @see [Wiki](https://bs-angular-zen.web.app/docs/zen/additional-documentation/coremodule/destroyable-(abstract).html) for full guide. * * @export * @abstract * @class Destroyable * @implements {OnDestroy} */ export declare abstract class Destroyable implements OnDestroy { /** * Emits a value when `ngOnDestroy()` is called. * Pipe together with `takeUntil()` to auto unsubscribe from your observables. * * @example * observable.pipe(takeUntil(this.destroyed)).subscribe(...); * * @protected * @type {Subject<void>} */ protected readonly destroyed: Subject<void>; /** * A list of all subscriptions manually added using the `subscribe()` method. * These are automatically unsubscribed when `ngOnDestroy()` is called. * * @protected * @type {Subscription} */ protected readonly subscriptions: Subscription; ngOnDestroy(): void; /** * Subscribes to an observable and stores the subscription for automatic disposal. * When `ngOnDestroy()` is called, all subscriptions created with this method will unsubscribe. * * @protected * @template T The type of data the observable will emit. * @param {Observable<T>} observable The observable to subscribe to. * @param {(value: T) => void} [next] (Optional) A callback function to execute on each emission of the observable. * @param {(error: any) => void} [error] (Optional) A callback function to execute when the observable errors. * @param {() => void} [complete] (Optional) A callback function to execute when the observable completes. * @returns {Subscription} The subscription created for the observable. */ protected subscribe<T>(observable: Observable<T>, next?: (value: T) => void, error?: (error: unknown) => void, complete?: () => void): Subscription; /** * Subscribes to an observable and stores the subscription for automatic disposal. * When `ngOnDestroy()` is called, all subscriptions created with this method will unsubscribe. * * @protected * @template T The type of data the observable will emit. * @param {Observable<T>} observable The observable to subscribe to. * @param {PartialObserver<T>} [observer] The observer that will handle observable events. * @returns {Subscription} The subscription created for the observable. */ protected subscribe<T>(observable: Observable<T>, observer?: PartialObserver<T>): Subscription; static ɵfac: i0.ɵɵFactoryDeclaration<Destroyable, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<Destroyable, never, never, {}, {}, never, never, false>; }