UNPKG

@ngx-cocktail/destroyable

Version:

The library contains code for destoyable feature.

51 lines (45 loc) 1.67 kB
import * as i0 from '@angular/core'; import { Directive } from '@angular/core'; import { Subject } from 'rxjs'; var _a; const destroySubject = Symbol('destroyed'); class Destroyed { constructor() { this[_a] = new Subject(); this.destroyed$ = this[destroySubject].asObservable(); } ngOnDestroy() { this[destroySubject].next(null); this[destroySubject].complete(); } } _a = destroySubject; Destroyed.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Destroyed, deps: [], target: i0.ɵɵFactoryTarget.Directive }); Destroyed.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.2", type: Destroyed, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Destroyed, decorators: [{ type: Directive }] }); function DestroyableFeature() { return (directiveDef) => { const { factory, type } = directiveDef; const { ngOnDestroy } = directiveDef.type.prototype; directiveDef.factory = () => { const instance = factory?.(type); const destroyed = Reflect.construct(Destroyed, []); Object.assign(instance, destroyed); directiveDef.type.prototype.ngOnDestroy = function () { ngOnDestroy?.call(this); destroyed.ngOnDestroy?.call(this); }; return instance; }; }; } /* * Public API Surface of destroyable */ /** * Generated bundle index. Do not edit. */ export { DestroyableFeature, Destroyed }; //# sourceMappingURL=ngx-cocktail-destroyable.mjs.map