1
+ // Type definitions for observe-js v0.5.5
2
+ // Project: https://github.com/Polymer/observe-js
3
+ // Definitions by: Oliver Herrmann <https://github.com/herrmanno/>
4
+ // Definitions: https://github.com/borisyankov/DefinitelyTyped
5
+
6
+ declare module observejs {
7
+
8
+ /*----------------------
9
+ Observable
10
+ ----------------------*/
11
+
12
+ interface Observable {
13
+ /**
14
+ * Begins observation.
15
+ * @param onChange the function that gets invoked if a change is detected
16
+ * @param the target of observation
17
+ */
18
+ open ( onChange :( newValue :any , oldValue :any ) => any , receiver ?:any ) :void
19
+
20
+ /**
21
+ * Report any changes now (does nothing if there are no changes to report).
22
+ */
23
+ deliver ( ) : void
24
+
25
+ /**
26
+ * If there are changes to report, ignore them. Returns the current value of the observation.
27
+ */
28
+ discardChanges ( ) :void
29
+
30
+ /**
31
+ * Ends observation. Frees resources and drops references to observed objects.
32
+ */
33
+ close ( ) :void
34
+ }
35
+
36
+
37
+ /*----------------------
38
+ PathObserver
39
+ ----------------------*/
40
+
41
+ interface PathObserver_static {
42
+ /**
43
+ * Constructor
44
+ * @param receiver the target for observation
45
+ * @param path specifies the paht to observe. If path === '' the receiver itself gets observed.
46
+ * @param defaultValue the defaultValue
47
+ */
48
+ new ( receiver :any , path :string , defaultValue ?:any ) : PathObserver_instance
49
+ }
50
+
51
+ interface PathObserver_instance extends Observable {
52
+ /**
53
+ * sets the observed value without notifying about the change.
54
+ * @param value the value to set
55
+ */
56
+ setValue ( value :any ) : void
57
+ }
58
+
59
+ /**
60
+ * Observes a "value-at-a-path" from a given object:
61
+ */
62
+ var PathObserver : PathObserver_static
63
+
64
+
65
+ /*----------------------
66
+ ArrayObserver
67
+ ----------------------*/
68
+
69
+ interface splice {
70
+
71
+ /**
72
+ * the index position that the change occured
73
+ */
74
+ index :number
75
+
76
+ /**
77
+ * an array of values representing the sequence of removed elements
78
+ */
79
+ removed : Array < any >
80
+
81
+ /**
82
+ * the number of element which were inserted
83
+ */
84
+ addedCount :number
85
+ }
86
+
87
+ interface ArrayObserver_static {
88
+
89
+ /**
90
+ * Constructor
91
+ * @param receiver the target for observation
92
+ */
93
+ new ( receiver :Array < any > ) : ArrayObserver_instance
94
+
95
+ /**
96
+ * transforms a copy of an old state of an array into a copy of its current state.
97
+ * @param previous array of old state
98
+ * @param current array of current state
99
+ * @param splices splices to apply
100
+ */
101
+ applySplices ( previous :Array < any > , current :Array < any > , splices :Array < splice > ) :void
102
+ }
103
+
104
+ interface ArrayObserver_instance extends Observable {
105
+ open ( onChange :( splices :Array < splice > ) => any ) :void
106
+ }
107
+
108
+ /**
109
+ * ArrayObserver observes the index-positions of an Array and reports changes as the minimal set of "splices" which would have had the same effect.
110
+ */
111
+ var ArrayObserver : ArrayObserver_static
112
+
113
+
114
+ /*----------------------
115
+ ObjectObserver
116
+ ----------------------*/
117
+
118
+ interface Properties {
119
+ [ key :string ] :any
120
+ }
121
+
122
+ interface ObjectObserver_static {
123
+
124
+ /**
125
+ * Constructor
126
+ * @param receiver the target for observation
127
+ */
128
+ new ( receiver :any ) : ObjectObserver_instance
129
+ }
130
+
131
+ interface ObjectObserver_instance extends Observable {
132
+ open ( onChange :( added :Properties , removed :Properties , changed :Properties , getOldValueFn :( property :string ) => any ) => any ) :void
133
+ }
134
+
135
+ /**
136
+ * Observes the set of own-properties of an object and their values
137
+ */
138
+ var ObjectObserver : ObjectObserver_static
139
+
140
+
141
+ /*----------------------
142
+ CompounObserver
143
+ ----------------------*/
144
+
145
+ interface CompoundObserver_static {
146
+
147
+ /**
148
+ * Constructor
149
+ */
150
+ new ( ) : CompoundObserver_instance
151
+ }
152
+
153
+ interface CompoundObserver_instance extends Observable {
154
+ open ( onChange :( newValues :Array < any > , oldValue :Array < any > ) => any ) :void
155
+
156
+ /**
157
+ * Adds the receivers property at the specified path to the list of observables.
158
+ * @param receiver the target for observation
159
+ * @param path specifies the paht to observe. If path === '' the receiver itself gets observed.
160
+ */
161
+ addPath ( receiver :any , path :string ) :void
162
+
163
+ /**
164
+ * Adds an Observer to the list of observables.
165
+ */
166
+ addObserver ( observer :Observable ) :void
167
+
168
+ }
169
+
170
+ /**
171
+ * CompoundObserver allows simultaneous observation of multiple paths and/or Observables.
172
+ */
173
+ var CompoundObserver : CompoundObserver_static
174
+
175
+
176
+
177
+ /*----------------------
178
+ ObserverTransform
179
+ ----------------------*/
180
+
181
+ interface ObserverTransform_static {
182
+
183
+ /**
184
+ * Constructor
185
+ * @param observer the observer to transform
186
+ * @param getValue function that proxys getting a value
187
+ * @param setValue function that proxys setting a value
188
+ */
189
+ new ( observer :Observable , getValue :( value :any ) => any , setValue :( value :any ) => any ) : ObserverTransform_instance
190
+
191
+ /**
192
+ * Constructor
193
+ * @param observer the observer to transform
194
+ * @param valueFn function that gets invoked with all observed values. May return a single new value.
195
+ */
196
+ new ( observer :Observable , valueFn :( values :Array < any > ) => any ) : ObserverTransform_instance
197
+ }
198
+
199
+ interface ObserverTransform_instance extends Observable {
200
+ /**
201
+ * sets the observed value without notifying about the change.
202
+ * @param value the value to set
203
+ */
204
+ setValue ( value :any ) : void
205
+ }
206
+
207
+ /**
208
+ * CompoundObserver allows simultaneous observation of multiple paths and/or Observables.
209
+ */
210
+ var ObserverTransform : ObserverTransform_static
211
+
212
+
213
+ /*----------------------
214
+ Path
215
+ ----------------------*/
216
+
217
+ interface Path {
218
+
219
+ /**
220
+ * Returns the current value of the path from the provided object. If eval() is available,
221
+ * a compiled getter will be used for better performance. Like PathObserver above, undefined
222
+ * is returned unless you provide an overriding defaultValue.
223
+ */
224
+ getValueFrom ( object :any , defaultValue :any ) : any
225
+
226
+ /**
227
+ * Attempts to set the value of the path from the provided object. Returns true IFF the path
228
+ * was reachable and set.
229
+ */
230
+ getValueFrom ( object :any , newValue :any ) : any
231
+ }
232
+ }
233
+
234
+ declare module "observejs" {
235
+ var PathObserver : typeof observejs . PathObserver ;
236
+ var ArrayObserver : typeof observejs . ArrayObserver ;
237
+ var ObjectObserver : typeof observejs . ObjectObserver ;
238
+ var CompoundObserver : typeof observejs . CompoundObserver ;
239
+ var ObserverTransform : typeof observejs . ObserverTransform ;
240
+ var Path : observejs . Path ;
241
+
242
+ export {
243
+ PathObserver ,
244
+ ArrayObserver ,
245
+ ObjectObserver ,
246
+ CompoundObserver ,
247
+ ObserverTransform ,
248
+ Path
249
+ } ;
250
+ }
0 commit comments