forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
observe-js.d.ts
250 lines (197 loc) · 6.19 KB
/
observe-js.d.ts
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
// Type definitions for observe-js v0.5.5
// Project: https://github.com/Polymer/observe-js
// Definitions by: Oliver Herrmann <https://github.com/herrmanno/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module observejs {
/*----------------------
Observable
----------------------*/
interface Observable {
/**
* Begins observation.
* @param onChange the function that gets invoked if a change is detected
* @param the target of observation
*/
open(onChange:(newValue:any, oldValue:any)=>any, receiver?:any):void
/**
* Report any changes now (does nothing if there are no changes to report).
*/
deliver(): void
/**
* If there are changes to report, ignore them. Returns the current value of the observation.
*/
discardChanges():void
/**
* Ends observation. Frees resources and drops references to observed objects.
*/
close():void
}
/*----------------------
PathObserver
----------------------*/
interface PathObserver_static {
/**
* Constructor
* @param receiver the target for observation
* @param path specifies the paht to observe. If path === '' the receiver itself gets observed.
* @param defaultValue the defaultValue
*/
new(receiver:any, path:string, defaultValue?:any): PathObserver_instance
}
interface PathObserver_instance extends Observable {
/**
* sets the observed value without notifying about the change.
* @param value the value to set
*/
setValue(value:any): void
}
/**
* Observes a "value-at-a-path" from a given object:
*/
var PathObserver: PathObserver_static
/*----------------------
ArrayObserver
----------------------*/
interface splice {
/**
* the index position that the change occured
*/
index:number
/**
* an array of values representing the sequence of removed elements
*/
removed: Array<any>
/**
* the number of element which were inserted
*/
addedCount:number
}
interface ArrayObserver_static {
/**
* Constructor
* @param receiver the target for observation
*/
new(receiver:Array<any>): ArrayObserver_instance
/**
* transforms a copy of an old state of an array into a copy of its current state.
* @param previous array of old state
* @param current array of current state
* @param splices splices to apply
*/
applySplices(previous:Array<any>, current:Array<any>, splices:Array<splice>):void
}
interface ArrayObserver_instance extends Observable {
open(onChange:(splices:Array<splice>)=>any):void
}
/**
* ArrayObserver observes the index-positions of an Array and reports changes as the minimal set of "splices" which would have had the same effect.
*/
var ArrayObserver: ArrayObserver_static
/*----------------------
ObjectObserver
----------------------*/
interface Properties {
[key:string]:any
}
interface ObjectObserver_static {
/**
* Constructor
* @param receiver the target for observation
*/
new(receiver:any): ObjectObserver_instance
}
interface ObjectObserver_instance extends Observable {
open(onChange:(added:Properties, removed:Properties, changed:Properties, getOldValueFn:(property:string)=>any)=>any):void
}
/**
* Observes the set of own-properties of an object and their values
*/
var ObjectObserver: ObjectObserver_static
/*----------------------
CompounObserver
----------------------*/
interface CompoundObserver_static {
/**
* Constructor
*/
new(): CompoundObserver_instance
}
interface CompoundObserver_instance extends Observable {
open(onChange:(newValues:Array<any>, oldValue:Array<any>)=>any):void
/**
* Adds the receivers property at the specified path to the list of observables.
* @param receiver the target for observation
* @param path specifies the paht to observe. If path === '' the receiver itself gets observed.
*/
addPath(receiver:any, path:string):void
/**
* Adds an Observer to the list of observables.
*/
addObserver(observer:Observable):void
}
/**
* CompoundObserver allows simultaneous observation of multiple paths and/or Observables.
*/
var CompoundObserver: CompoundObserver_static
/*----------------------
ObserverTransform
----------------------*/
interface ObserverTransform_static {
/**
* Constructor
* @param observer the observer to transform
* @param getValue function that proxys getting a value
* @param setValue function that proxys setting a value
*/
new(observer:Observable, getValue:(value:any)=>any, setValue:(value:any)=>any): ObserverTransform_instance
/**
* Constructor
* @param observer the observer to transform
* @param valueFn function that gets invoked with all observed values. May return a single new value.
*/
new(observer:Observable, valueFn:(values:Array<any>)=>any): ObserverTransform_instance
}
interface ObserverTransform_instance extends Observable {
/**
* sets the observed value without notifying about the change.
* @param value the value to set
*/
setValue(value:any): void
}
/**
* CompoundObserver allows simultaneous observation of multiple paths and/or Observables.
*/
var ObserverTransform: ObserverTransform_static
/*----------------------
Path
----------------------*/
interface Path {
/**
* Returns the current value of the path from the provided object. If eval() is available,
* a compiled getter will be used for better performance. Like PathObserver above, undefined
* is returned unless you provide an overriding defaultValue.
*/
getValueFrom(object:any, defaultValue:any): any
/**
* Attempts to set the value of the path from the provided object. Returns true IFF the path
* was reachable and set.
*/
getValueFrom(object:any, newValue:any): any
}
}
declare module "observe-js" {
var PathObserver: typeof observejs.PathObserver;
var ArrayObserver: typeof observejs.ArrayObserver;
var ObjectObserver: typeof observejs.ObjectObserver;
var CompoundObserver: typeof observejs.CompoundObserver;
var ObserverTransform: typeof observejs.ObserverTransform;
var Path: observejs.Path;
export {
PathObserver,
ArrayObserver,
ObjectObserver,
CompoundObserver,
ObserverTransform,
Path
};
}