forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependency-observable.d.ts
More file actions
293 lines (270 loc) · 11.5 KB
/
dependency-observable.d.ts
File metadata and controls
293 lines (270 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/**
* Contains the DependencyObservable class, which represents an extended Observable object that uses Property instances for value backing mechanism.
*/
declare module "ui/core/dependency-observable" {
import observable = require("data/observable");
/**
* Interface used by Propery 'defaultValueGetter' function to specify if the default value returned by the native instance can be cached or not.
* One example is - android.widget.Button background. It is state drawable so it cannot be reused/cached.
*/
export interface NativeValueResult {
result: any;
cacheable: boolean;
}
/**
* Represents a special Property which supports changed callback, metadata and value validation.
*/
export class Property {
/**
* Creates a new Property instance.
* @param name The name of the property.
* @param ownerType The name of class that registers this property.
* @param metadata The PropertyMetadata object associated with this property.
* @param valueConverter A function that can create an instance of the property type given a string. Used when parsing CSS and XML attribute values which are strings.
*/
constructor(name: string, ownerType: string, metadata: PropertyMetadata, valueConverter?: (value: string) => any);
/**
* Gets the name of the property. This is a read-only property.
*/
name: string;
/**
* Gets the id of the property. This is used for fast lookup. This is a read-only property.
*/
id: number;
/**
* Gets the PropertyMetadata object associated with the property. This is a read-only property.
*/
metadata: PropertyMetadata;
/**
* Gets the valueConverter function associated with the property. This is a read-only property.
*/
valueConverter: (value: string) => any
/**
* Gets or sets the defaultValueGetter function used to get the default value for this property.
* If default value is 'undefined' and this property is set this function will be used to extract the default value from the native instance.
*/
defaultValueGetter: (instance: DependencyObservable) => NativeValueResult;
}
/**
* Represents an Object that describes a Property instance.
*/
export class PropertyMetadata {
/**
* Creates a new PropertyMetadata instance.
* @param defaultValue The default value for the property. E.g. 0 for a numeric property.
* @param options An optional parameter that specifies how the associated property should be processed by the visual tree. Valid values are one or more bitwise combinations from the PropertyMetadataSettings module.
* @param onChanged An optional callback that will be raised whenever the associated property changes for any DependencyObservable instance that uses the property to store a value.
* @param onValidateValue An optional callback that will be raised prior to a change of the associated property for any DependencyObservable instance that uses the property.
* @param equalityComparer An optional function that used to compare if two property values are equal.
*/
constructor(
defaultValue: any,
options?: number,
onChanged?: PropertyChangedCallback,
onValidateValue?: PropertyValidationCallback,
equalityComparer?: PropertyEqualityComparer);
/**
* Gets the options parameter passed to the constructor of this instance. This is a read-only property.
*/
options: number;
/**
* Gets the default value parameter passed to the constructor of this instance. This is a read-only property.
*/
defaultValue: any;
/**
* Gets or sets the callback to be raised whenever the associated property changes for any DependencyObservable instance that uses the property to store a value.
*/
onValueChanged: PropertyChangedCallback;
/**
* Gets or sets the callback to be raised whenever the associated property is about to change for any DependencyObservable instance that uses the property to store a value.
*/
onValidateValue: PropertyValidationCallback;
/**
* Gets function that used to compare if two property values are equal.
*/
equalityComparer: PropertyEqualityComparer;
/**
* Checks whether the PropertyMetadataSettings.affectsLayout bit is present in the options value.
*/
affectsLayout: boolean;
/**
* Checks whether the PropertyMetadataSettings.Inheritable bit is present in the options value.
*/
inheritable: boolean;
/**
* Checks whether the PropertyMetadataSettings.AffectsStyle bit is present in the options value.
*/
affectsStyle: boolean;
}
/**
* The data for the event raised when a value of a Property changes for a DependencyObservable instance.
*/
export interface PropertyChangeData extends observable.EventData {
/**
* The Property associated with the change.
*/
property: Property;
/**
* The old property value.
*/
oldValue: any;
/**
* The new property value.
*/
newValue: any;
}
/**
* Defines the signature of the function that handles the propertyChanged event.
*/
export interface PropertyChangedCallback {
(data: PropertyChangeData): void;
}
/**
* Defines the signature of the function that handles the validateValue event.
*/
export interface PropertyValidationCallback {
(value: any): boolean;
}
/**
* Defines the signature of the function that compares if two property values are equal.
*/
export interface PropertyEqualityComparer {
(x: any, y: any): boolean;
}
/**
* Represents an Object that is used to back a value for a Property in a DependencyObservable Object instance.
*/
export class PropertyEntry {
/**
* Creates a new PropertyEntry instance, associated with the specified Property.
* @param property The Property this entry is attached to.
*/
constructor(property: Property);
/**
* Resets effective value and all the modifiers available for this entry.
*/
resetValue(): void;
/**
* Gets the Property instance this entry is associated with. This is a read-only property.
*/
property: Property;
/**
* Gets the effective value of this entry.
* The value is composed depending on the current valueSource value, using the following priority:
* 1. VisualState
* 2. Local
* 3. Css
* 4. Inherited
* 5. Default
*/
effectiveValue: any;
/**
* Gets the source of the current effective value for this entry. The available options for this property are defined in the ValueSource namespace.
*/
valueSource: number;
/**
* Gets or sets the local value for this entry. This will trigger re-evaluation of the current effective value.
*/
localValue: any;
/**
* Gets or sets the inherited value for this entry. This will trigger re-evaluation of the current effective value.
*/
inheritedValue: any;
/**
* Gets or sets the css value for this entry. This will trigger re-evaluation of the current effective value.
*/
cssValue: any;
/**
* Gets or sets the visual-state value for this entry. This will trigger re-evaluation of the current effective value.
*/
visualStateValue: any;
}
/**
* Represents an extended Observable Object that uses Property instances for value backing mechanism.
* This routine allows for various value modifiers per Property, which is used for inheritance, data-binding and styling purposes.
*/
export class DependencyObservable extends observable.Observable {
// TODO: Do we want to expose the get/setValue methods as public?
/**
* Gets a value for the property.
* @param property - A dependency property to retrieve a value for.
*/
_getValue(property: Property): any;
/**
* Gets the value source (local, inherited) of a property.
* @param property - A dependency property to retrieve a value source for.
*/
_getValueSource(property: Property): number;
/**
* Sets a value for a property.
* @param property - A dependency property to set.
* @param value - The new value.
* @param source(optional) - The value source (default is local).
*/
_setValue(property: Property, value: any, source?: number): void;
/**
* Resets a value for a property.
* @param - property - A dependency property to reset.
* @param source(optional) - The value source (default is local).
*/
_resetValue(property: Property, source?: number): void;
/**
* Handler for property changed event.
* @param property - A dependency property indentifier.
* @param oldValue - The old value of the property.
* @param newValue - The new value of the property.
*/
_onPropertyChanged(property: Property, oldValue: any, newValue: any): void;
/**
* Iterates all the properties which have a PropertyEntry registered for this instance.
*/
_eachSetProperty(callback: (property: Property) => boolean): void;
//@endprivate
}
/**
* Lists the possible values for the PropertyMetadata.options property. Each actual numeric value is a power of two allowing for bitwise operations.
*/
export module PropertyMetadataSettings {
/**
* No options are specified. This is the default value.
*/
export var None: number;
/**
* A change in the Property associated with the metadata will invalidate the layout.
*/
export var AffectsLayout;
/**
* The Property associated with the metadata is inheritable and its value should be propagated down in the visual tree.
*/
export var Inheritable: number;
/**
* A change in the Property associated with the metadata will cause all CSS styles to be re-evaluated for for owning element.
*/
export var AffectsStyle: number;
}
/**
* Lists the possible values for the PropertyEntry.valueSource property.
*/
export module ValueSource {
/**
* Default value, coming from the PropertyMetadata.defaultValue.
*/
export var Default: number;
/**
* Inherited value, coming from the logical parent of the current DependencyObservable instance.
*/
export var Inherited: number;
/**
* Css value, coming a css selector and rule that matches the current DependencyObservable instance.
*/
export var Css: number;
/**
* Local value, set directly to the current DependencyObservable instance.
*/
export var Local: number;
/**
* VisualState value, coming from a visual-state css selector. E.g. { button:pressed }.
*/
export var VisualState: number;
}
}