Merge pull request #8879 from kalutkaz/updateCoerceBoolean
Update cource Decorators
This commit is contained in:
commit
103f41d16c
@ -22,7 +22,14 @@ 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 => {
|
||||||
|
if (!!propertyDescriptor && !!propertyDescriptor.set) {
|
||||||
|
const original = propertyDescriptor.set;
|
||||||
|
|
||||||
|
propertyDescriptor.set = function(next) {
|
||||||
|
original.apply(this, [coerceBooleanProperty(next)]);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
const getter = function() {
|
const getter = function() {
|
||||||
return this['__' + key];
|
return this['__' + key];
|
||||||
};
|
};
|
||||||
@ -37,10 +44,18 @@ export const coerceBoolean = () => (target: any, key: string): void => {
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const coerceNumber = () => (target: any, key: string): void => {
|
export const coerceNumber = () => (target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
|
||||||
const getter = function(): number {
|
if (!!propertyDescriptor && !!propertyDescriptor.set) {
|
||||||
|
const original = propertyDescriptor.set;
|
||||||
|
|
||||||
|
propertyDescriptor.set = function(next) {
|
||||||
|
original.apply(this, [coerceNumberProperty(next)]);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const getter = function() {
|
||||||
return this['__' + key];
|
return this['__' + key];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,10 +69,18 @@ export const coerceNumber = () => (target: any, key: string): void => {
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const coerceCssPixelValue = () => (target: any, key: string): void => {
|
export const coerceCssPixelValue = () => (target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
|
||||||
const getter = function(): string {
|
if (!!propertyDescriptor && !!propertyDescriptor.set) {
|
||||||
|
const original = propertyDescriptor.set;
|
||||||
|
|
||||||
|
propertyDescriptor.set = function(next) {
|
||||||
|
original.apply(this, [coerceCssPixelValueAngular(next)]);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const getter = function() {
|
||||||
return this['__' + key];
|
return this['__' + key];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,10 +94,18 @@ export const coerceCssPixelValue = () => (target: any, key: string): void => {
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const coerceArray = () => (target: any, key: string): void => {
|
export const coerceArray = () => (target: any, key: string, propertyDescriptor?: PropertyDescriptor): void => {
|
||||||
const getter = function(): any[] {
|
if (!!propertyDescriptor && !!propertyDescriptor.set) {
|
||||||
|
const original = propertyDescriptor.set;
|
||||||
|
|
||||||
|
propertyDescriptor.set = function(next) {
|
||||||
|
original.apply(this, [coerceArrayAngular(next)]);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const getter = function() {
|
||||||
return this['__' + key];
|
return this['__' + key];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,10 +119,19 @@ export const coerceArray = () => (target: any, key: string): void => {
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const coerceStringArray = (separator?: string | RegExp) => (target: any, key: string): void => {
|
export const coerceStringArray = (separator?: string | RegExp) =>
|
||||||
const getter = function(): string[] {
|
(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];
|
return this['__' + key];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,4 +145,5 @@ export const coerceStringArray = (separator?: string | RegExp) => (target: any,
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user