ngx-decorate
Version:
Useful decorators for Angular 2 and above
38 lines • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Call .markForCheck() on the change detector ref whenever this property is written to.
*
* @param propName Property at which the change detector can be found
* @param conf Optional configuration
*/
function CdrProp(propName, conf = {}) {
return (target, key) => {
const sym = Symbol(`value:${key.toString()}`);
const defaultDescriptor = {
configurable: true,
enumerable: true
};
Object.defineProperties(target, {
[sym]: {
configurable: false,
enumerable: false,
value: conf.default || target[key],
writable: true
},
[key]: Object.assign(defaultDescriptor, conf.desc || {}, {
get() {
return this[sym];
},
set(v) {
this[sym] = v;
if (!conf.destroyed || !this[conf.destroyed]) {
this[propName].markForCheck();
}
}
})
});
};
}
exports.CdrProp = CdrProp;
//# sourceMappingURL=CdrProp.js.map