@@ -38,7 +38,7 @@ const enum ValueSource {
38
38
Local = 3
39
39
}
40
40
41
- export class Property < T extends ViewBase , U > implements PropertyDescriptor , definitions . Property < T , U > {
41
+ export class Property < T extends ViewBase , U > implements TypedPropertyDescriptor < U > , definitions . Property < T , U > {
42
42
private registered : boolean ;
43
43
44
44
public readonly name : string ;
@@ -174,40 +174,20 @@ export class Property<T extends ViewBase, U> implements PropertyDescriptor, defi
174
174
}
175
175
}
176
176
177
- export class CoercibleProperty < T extends ViewBase , U > implements PropertyDescriptor , definitions . CoercibleProperty < T , U > {
178
- private registered : boolean ;
179
- private readonly name : string ;
180
- public readonly key : symbol ;
181
- public readonly native : symbol ;
182
- public readonly defaultValueKey : symbol ;
183
- public readonly defaultValue : U ;
184
- public readonly nativeValueChange : ( owner : T , value : U ) => void ;
185
-
186
- public readonly get : ( ) => U ;
187
- public readonly set : ( value : U ) => void ;
188
- public readonly enumerable : boolean = true ;
189
- public readonly configurable : boolean = true ;
190
-
177
+ export class CoercibleProperty < T extends ViewBase , U > extends Property < T , U > implements definitions . CoercibleProperty < T , U > {
191
178
public readonly coerce : ( target : T ) => void ;
192
179
193
180
constructor ( options : definitions . CoerciblePropertyOptions < T , U > ) {
194
- const name = options . name ;
195
- this . name = name ;
196
-
F438
197
- const key = Symbol ( name + ":propertyKey" ) ;
198
- this . key = key ;
199
-
200
- const native : symbol = Symbol ( name + ":nativeKey" ) ;
201
- this . native = native ;
181
+ super ( options ) ;
202
182
203
- const defaultValueKey = Symbol ( name + ":nativeDefaultValue" ) ;
204
- this . defaultValueKey = defaultValueKey ;
183
+ const name = options . name ;
184
+ const key = this . key ;
185
+ const native : symbol = this . native ;
186
+ const defaultValueKey = this . defaultValueKey ;
187
+ const defaultValue : U = this . defaultValue ;
205
188
206
189
const coerceKey = Symbol ( name + ":coerceKey" ) ;
207
190
208
- const defaultValue : U = options . defaultValue ;
209
- this . defaultValue = defaultValue ;
210
-
211
191
const eventName = name + "Change" ;
212
192
const affectsLayout : boolean = options . affectsLayout ;
213
193
const equalityComparer = options . equalityComparer ;
@@ -218,8 +198,8 @@ export class CoercibleProperty<T extends ViewBase, U> implements PropertyDescrip
218
198
this . coerce = function ( target : T ) : void {
219
199
const originalValue : U = coerceKey in target ? target [ coerceKey ] : defaultValue ;
220
200
// need that to make coercing but also fire change events
221
- this . set . call ( target , originalValue ) ;
222
- } ;
201
+ target [ name ] = originalValue ;
202
+ }
223
203
224
204
this . set = function ( this : T , value : U ) : void {
225
205
const reset = value === unsetValue ;
@@ -283,46 +263,7 @@ export class CoercibleProperty<T extends ViewBase, U> implements PropertyDescrip
283
263
this . requestLayout ( ) ;
284
264
}
285
265
}
286
- } ;
287
-
288
- this . get = function ( ) : U {
289
- return key in this ? this [ key ] : defaultValue ;
290
- } ;
291
-
292
- this . nativeValueChange = function ( owner : T , value : U ) : void {
293
- const currentValue = key in owner ? owner [ key ] : defaultValue ;
294
- const changed = equalityComparer ? ! equalityComparer ( currentValue , value ) : currentValue !== value ;
295
- if ( changed ) {
296
- owner [ key ] = value ;
297
- owner [ coerceKey ] = value ;
298
- if ( valueChanged ) {
299
- valueChanged ( owner , currentValue , value ) ;
300
- }
301
-
302
- if ( owner . hasListeners ( eventName ) ) {
303
- owner . notify ( {
304
- eventName : eventName ,
305
- propertyName : name ,
306
- object : owner ,
307
- value : value
308
- } ) ;
309
- }
310
-
311
- if ( affectsLayout ) {
312
- owner . requestLayout ( ) ;
313
- }
314
- }
315
- } ;
316
-
317
- symbolPropertyMap [ key ] = this ;
318
- }
319
-
320
- public register ( cls : { prototype : T } ) : void {
321
- if ( this . registered ) {
322
- throw new Error ( `Property ${ this . name } already registered.` ) ;
323
266
}
324
- this . registered = true ;
325
- Object . defineProperty ( cls . prototype , this . name , this ) ;
326
267
}
327
268
}
328
269
@@ -832,7 +773,7 @@ function inheritableCssPropertyValuesOn(style: Style): Array<{ property: Inherit
832
773
return array ;
833
774
}
834
775
835
- export function applyNativeSetters ( view : ViewBase ) : void {
776
+ export function initNativeView ( view : ViewBase ) : void {
836
777
let symbols = ( < any > Object ) . getOwnPropertySymbols ( view ) ;
837
778
for ( let symbol of symbols ) {
838
779
const property : Property < any , any > = symbolPropertyMap [ symbol ] ;
@@ -873,6 +814,44 @@ export function applyNativeSetters(view: ViewBase): void {
873
814
}
874
815
}
875
816
817
+ export function resetNativeView ( view : ViewBase ) : void {
818
+ let symbols = ( < any > Object ) . getOwnPropertySymbols ( view ) ;
819
+ for ( let symbol of symbols ) {
820
+ const property : Property < any , any > = symbolPropertyMap [ symbol ] ;
821
+ if ( ! property ) {
822
+ continue ;
823
+ }
824
+
825
+ const native = property . native ;
826
+ if ( native in view ) {
827
+ view [ native ] = view [ property . defaultValueKey ] ;
828
+ delete view [ property . defaultValueKey ] ;
829
+ }
830
+
831
+ // This will not call propertyChange!!!
832
+ delete view [ property . key ] ;
833
+ }
834
+
835
+ const style = view . style ;
836
+
837
+ symbols = ( < any > Object ) . getOwnPropertySymbols ( style ) ;
838
+ for ( let symbol of symbols ) {
839
+ const property : CssProperty < any , any > = cssSymbolPropertyMap [ symbol ] ;
840
+ if ( ! property ) {
841
+ continue ;
842
+ }
843
+
844
+ const native = property . native ;
845
+ if ( native in view ) {
846
+ view [ native ] = style [ property . defaultValueKey ] ;
847
+ delete style [ property . defaultValueKey ] ;
848
+ }
849
+
850
+ // This will not call propertyChange!!!
851
+ delete style [ property . key ] ;
852
+ }
853
+ }
854
+
876
855
export function clearInheritedProperties ( view : ViewBase ) : void {
877
856
for ( let prop of inheritableProperties ) {
878
857
const sourceKey = prop . sourceKey ;
@@ -902,26 +881,6 @@ export function resetCSSProperties(style: Style): void {
902
881
}
903
882
}
904
883
905
- export function resetStyleProperties ( style : Style ) : void {
906
- let symbols = ( < any > Object ) . getOwnPropertySymbols ( style ) ;
907
- const view = style . view ;
908
- for ( let symbol of symbols ) {
909
- const property : CssProperty < any , any > = symbolPropertyMap [ symbol ] ;
910
- if ( ! property ) {
911
- continue ;
912
- }
913
-
914
- const native = property . native ;
915
- if ( native in view ) {
916
- view [ native ] = style [ property . defaultValueKey ] ;
917
- delete style [ property . defaultValueKey ] ;
918
- }
919
-
920
- // This will not call propertyChange!!!
921
- delete style [ property . key ] ;
922
- }
923
- }
924
-
925
884
export function propagateInheritedProperties ( view : ViewBase ) : void {
926
885
const inheritablePropertyValues = inheritablePropertyValuesOn ( view ) ;
927
886
const inheritableCssPropertyValues = inheritableCssPropertyValuesOn ( view . style ) ;
@@ -966,4 +925,4 @@ export function makeParser<T>(isValid: (value: any) => boolean): (value: any) =>
966
925
throw new Error ( "Invalid value: " + value ) ;
967
926
}
968
927
} ;
969
- }
928
+ }
0 commit comments