diff --git a/packages/core/ui/core/properties/index.ts b/packages/core/ui/core/properties/index.ts index eef42a4cc..63af41eaf 100644 --- a/packages/core/ui/core/properties/index.ts +++ b/packages/core/ui/core/properties/index.ts @@ -3,7 +3,7 @@ import * as reduceCSSCalc from 'reduce-css-calc'; import { ViewBase } from '../view-base'; // Types. -import { WrappedValue, PropertyChangeData } from '../../../data/observable'; +import { PropertyChangeData, WrappedValue } from '../../../data/observable'; import { Trace } from '../../../trace'; import { Style } from '../../styling/style'; @@ -11,7 +11,7 @@ import { Style } from '../../styling/style'; import { profile } from '../../../profiling'; /** - * Value specifing that Property should be set to its initial value. + * Value specifying that Property should be set to its initial value. */ export const unsetValue: any = new Object(); @@ -183,6 +183,7 @@ export class Property implements TypedPropertyDescriptor< public get: () => U; public set: (value: U) => void; + public overrideHandlers: (options: PropertyOptions) => void; public enumerable = true; public configurable = true; @@ -206,10 +207,26 @@ export class Property implements TypedPropertyDescriptor< this.defaultValue = defaultValue; const eventName = propertyName + 'Change'; - const equalityComparer = options.equalityComparer; - const affectsLayout: boolean = options.affectsLayout; - const valueChanged = options.valueChanged; - const valueConverter = options.valueConverter; + + let equalityComparer = options.equalityComparer; + let affectsLayout: boolean = options.affectsLayout; + let valueChanged = options.valueChanged; + let valueConverter = options.valueConverter; + + this.overrideHandlers = function (options: PropertyOptions) { + if (typeof options.equalityComparer !== 'undefined') { + equalityComparer = options.equalityComparer; + } + if (typeof options.affectsLayout !== 'undefined') { + affectsLayout = options.affectsLayout; + } + if (typeof options.valueChanged !== 'undefined') { + valueChanged = options.valueChanged; + } + if (typeof options.valueConverter !== 'undefined') { + valueConverter = options.valueConverter; + } + }; const property = this; @@ -364,14 +381,32 @@ export class CoercibleProperty extends Property imp const coerceKey = Symbol(propertyName + ':coerceKey'); const eventName = propertyName + 'Change'; - const affectsLayout: boolean = options.affectsLayout; - const equalityComparer = options.equalityComparer; - const valueChanged = options.valueChanged; - const valueConverter = options.valueConverter; - const coerceCallback = options.coerceValue; + let affectsLayout: boolean = options.affectsLayout; + let equalityComparer = options.equalityComparer; + let valueChanged = options.valueChanged; + let valueConverter = options.valueConverter; + let coerceCallback = options.coerceValue; const property = this; + this.overrideHandlers = function (options: CoerciblePropertyOptions) { + if (typeof options.equalityComparer !== 'undefined') { + equalityComparer = options.equalityComparer; + } + if (typeof options.affectsLayout !== 'undefined') { + affectsLayout = options.affectsLayout; + } + if (typeof options.valueChanged !== 'undefined') { + valueChanged = options.valueChanged; + } + if (typeof options.valueConverter !== 'undefined') { + valueConverter = options.valueConverter; + } + if (typeof options.coerceValue !== 'undefined') { + coerceCallback = options.coerceValue; + } + }; + this.coerce = function (target: T): void { const originalValue: U = coerceKey in target ? target[coerceKey] : defaultValue; // need that to make coercing but also fire change events @@ -559,6 +594,8 @@ export class CssProperty implements CssProperty { public readonly defaultValueKey: symbol; public readonly defaultValue: U; + public overrideHandlers: (options: CssPropertyOptions) => void; + constructor(options: CssPropertyOptions) { const propertyName = options.name; this.name = propertyName; @@ -587,10 +624,25 @@ export class CssProperty implements CssProperty { this.defaultValue = defaultValue; const eventName = propertyName + 'Change'; - const affectsLayout: boolean = options.affectsLayout; - const equalityComparer = options.equalityComparer; - const valueChanged = options.valueChanged; - const valueConverter = options.valueConverter; + let affectsLayout: boolean = options.affectsLayout; + let equalityComparer = options.equalityComparer; + let valueChanged = options.valueChanged; + let valueConverter = options.valueConverter; + + this.overrideHandlers = function (options: CssPropertyOptions) { + if (typeof options.equalityComparer !== 'undefined') { + equalityComparer = options.equalityComparer; + } + if (typeof options.affectsLayout !== 'undefined') { + affectsLayout = options.affectsLayout; + } + if (typeof options.valueChanged !== 'undefined') { + valueChanged = options.valueChanged; + } + if (typeof options.valueConverter !== 'undefined') { + valueConverter = options.valueConverter; + } + }; const property = this; @@ -1015,6 +1067,7 @@ CssAnimationProperty.prototype.isStyleProperty = true; export class InheritedCssProperty extends CssProperty implements InheritedCssProperty { public setInheritedValue: (value: U) => void; + public overrideHandlers: (options: CssPropertyOptions) => void; constructor(options: CssPropertyOptions) { super(options); @@ -1027,14 +1080,29 @@ export class InheritedCssProperty extends CssProperty const defaultValueKey = this.defaultValueKey; const eventName = propertyName + 'Change'; - const defaultValue: U = options.defaultValue; - const affectsLayout: boolean = options.affectsLayout; - const equalityComparer = options.equalityComparer; - const valueChanged = options.valueChanged; - const valueConverter = options.valueConverter; + let defaultValue: U = options.defaultValue; + let affectsLayout: boolean = options.affectsLayout; + let equalityComparer = options.equalityComparer; + let valueChanged = options.valueChanged; + let valueConverter = options.valueConverter; const property = this; + this.overrideHandlers = function (options: CssPropertyOptions) { + if (typeof options.equalityComparer !== 'undefined') { + equalityComparer = options.equalityComparer; + } + if (typeof options.affectsLayout !== 'undefined') { + affectsLayout = options.affectsLayout; + } + if (typeof options.valueChanged !== 'undefined') { + valueChanged = options.valueChanged; + } + if (typeof options.valueConverter !== 'undefined') { + valueConverter = options.valueConverter; + } + }; + const setFunc = (valueSource: ValueSource) => function (this: T, boxedValue: any): void { const view = this.viewRef.get();