ngx-decorate
Version:
Useful decorators for Angular 2 and above
28 lines • 1.01 kB
JavaScript
import { ensureSymbol } from './lib/ensureSymbol';
import { HookManager } from './lib/HookManager';
import { _lazySubj } from './lib/symbols';
import { lazySubj } from './processors/lazy-subject';
/**
* Decorate a getter that returns a subject. The subject will automatically get completed
* when the component/service/pipe is destroyed.
*/
export function LazySubject() {
return (_target, key, desc) => {
const orig = desc.get;
if (!orig) {
throw new Error('LazySubject can only decorate getters');
}
desc.get = function () {
const value = orig.apply(this, arguments);
Object.defineProperty(this, key, {
configurable: true,
enumerable: desc.enumerable,
value
});
ensureSymbol(this, _lazySubj, []).push(value);
return value;
};
HookManager.for(_target).add(3 /* POST_DESTROY */, lazySubj);
};
}
//# sourceMappingURL=LazySubject.js.map