UNPKG

ngx-decorate

Version:

Useful decorators for Angular 2 and above

28 lines 1 kB
import { ensureSymbol } from './lib/ensureSymbol'; import { HookManager } from './lib/HookManager'; import { _subscrTo } from './lib/symbols'; import { subscribeTo } from './processors/subscribe-to'; import { unsubscribe } from './processors/unsubscribe'; /** * Subscribe to an observable and set its last emitted value to this property * * This decorator requires the ngOnInit hook and therefore will only work with directives and components. * * @param prop Property at which the observable resides * @param cfg Optional configuration */ export function SubscribeTo(prop, cfg) { if (cfg === void 0) { cfg = {}; } return function (target, key) { ensureSymbol(target, _subscrTo, []) .push({ cfg: cfg, source: prop, target: key }); var mgr = HookManager.for(target); mgr.add(2 /* POST_INIT */, subscribeTo); mgr.add(3 /* POST_DESTROY */, unsubscribe); }; } //# sourceMappingURL=SubscribeTo.js.map