Update decorators

This commit is contained in:
kalytka 2023-07-05 17:12:07 +03:00
parent e7fd826a85
commit afb4166322

View File

@ -47,8 +47,15 @@ export const coerceBoolean = () => (target: any, key: string, propertyDescriptor
}
};
export const coerceNumber = () => (target: any, key: string): void => {
const getter = function(): number {
export const coerceNumber = () => (target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
if (!!propertyDescriptor && !!propertyDescriptor.set) {
const original = propertyDescriptor.set;
propertyDescriptor.set = function(next) {
original.apply(this, [coerceNumberProperty(next)]);
};
} else {
const getter = function() {
return this['__' + key];
};
@ -62,10 +69,18 @@ export const coerceNumber = () => (target: any, key: string): void => {
enumerable: true,
configurable: true,
});
}
};
export const coerceCssPixelValue = () => (target: any, key: string): void => {
const getter = function(): string {
export const coerceCssPixelValue = () => (target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
if (!!propertyDescriptor && !!propertyDescriptor.set) {
const original = propertyDescriptor.set;
propertyDescriptor.set = function(next) {
original.apply(this, [coerceCssPixelValueAngular(next)]);
};
} else {
const getter = function() {
return this['__' + key];
};
@ -79,10 +94,18 @@ export const coerceCssPixelValue = () => (target: any, key: string): void => {
enumerable: true,
configurable: true,
});
}
};
export const coerceArray = () => (target: any, key: string): void => {
const getter = function(): any[] {
export const coerceArray = () => (target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
if (!!propertyDescriptor && !!propertyDescriptor.set) {
const original = propertyDescriptor.set;
propertyDescriptor.set = function(next) {
original.apply(this, [coerceArrayAngular(next)]);
};
} else {
const getter = function() {
return this['__' + key];
};
@ -96,10 +119,19 @@ export const coerceArray = () => (target: any, key: string): void => {
enumerable: true,
configurable: true,
});
}
};
export const coerceStringArray = (separator?: string | RegExp) => (target: any, key: string): void => {
const getter = function(): string[] {
export const coerceStringArray = (separator?: string | RegExp) =>
(target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
if (!!propertyDescriptor && !!propertyDescriptor.set) {
const original = propertyDescriptor.set;
propertyDescriptor.set = function(next) {
original.apply(this, [coerceStringArrayAngular(next, separator)]);
};
} else {
const getter = function() {
return this['__' + key];
};
@ -113,4 +145,5 @@ export const coerceStringArray = (separator?: string | RegExp) => (target: any,
enumerable: true,
configurable: true,
});
}
};