Browse Source

Update courceBoolean Decorator

pull/8879/head
kalytka 3 years ago
parent
commit
e7fd826a85
  1. 38
      ui-ngx/src/app/shared/decorators/coercion.ts

38
ui-ngx/src/app/shared/decorators/coercion.ts

@ -22,21 +22,29 @@ import {
coerceStringArray as coerceStringArrayAngular coerceStringArray as coerceStringArrayAngular
} from '@angular/cdk/coercion'; } from '@angular/cdk/coercion';
export const coerceBoolean = () => (target: any, key: string): void => { export const coerceBoolean = () => (target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
const getter = function() { if (!!propertyDescriptor && !!propertyDescriptor.set) {
return this['__' + key]; const original = propertyDescriptor.set;
};
propertyDescriptor.set = function(next) {
const setter = function(next: any) { original.apply(this, [coerceBooleanProperty(next)]);
this['__' + key] = coerceBooleanProperty(next); };
}; } else {
const getter = function() {
Object.defineProperty(target, key, { return this['__' + key];
get: getter, };
set: setter,
enumerable: true, const setter = function(next: any) {
configurable: true, this['__' + key] = coerceBooleanProperty(next);
}); };
Object.defineProperty(target, key, {
get: getter,
set: setter,
enumerable: true,
configurable: true,
});
}
}; };
export const coerceNumber = () => (target: any, key: string): void => { export const coerceNumber = () => (target: any, key: string): void => {

Loading…
Cancel
Save