@ngx-cocktail/destroyable
Version:
[](https://www.npmjs.com/package/@ngx-cocktail/destroyable) [](https://www.npmjs.com/package/@ngx-cockta
52 lines (46 loc) • 1.78 kB
JavaScript
import * as i0 from '@angular/core';
import { Directive } from '@angular/core';
import { Subject } from 'rxjs';
export { Features } from '@ngx-cocktail/common';
var _a;
const destroySubject = Symbol('destroyed');
class Destroyed {
constructor() {
this[_a] = new Subject();
this.destroyed$ = this[destroySubject].asObservable();
}
static { _a = destroySubject; }
ngOnDestroy() {
this[destroySubject].next(null);
this[destroySubject].complete();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: Destroyed, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.8", type: Destroyed, isStandalone: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", 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