UNPKG

20.6 kBTypeScriptView Raw
1// Type definitions for rx-lite-experimental 4.0
2// Project: https://github.com/Reactive-Extensions/RxJS
3// Definitions by: Igor Oleinikov <https://github.com/Igorbek>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/// <reference types="rx-lite"/>
7
8declare namespace Rx {
9 interface Observable<T> {
10 /**
11 * Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.
12 * This operator allows for a fluent style of writing queries that use the same sequence multiple times.
13 *
14 * @param selector Selector function which can use the source sequence as many times as needed, without sharing subscriptions to the source sequence.
15 * @returns An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
16 */
17 let<TResult>(selector: (source: Observable<T>) => Observable<TResult>): Observable<TResult>;
18
19 /**
20 * Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.
21 * This operator allows for a fluent style of writing queries that use the same sequence multiple times.
22 *
23 * @param selector Selector function which can use the source sequence as many times as needed, without sharing subscriptions to the source sequence.
24 * @returns An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
25 */
26 letBind<TResult>(selector: (source: Observable<T>) => Observable<TResult>): Observable<TResult>;
27
28 /**
29 * Repeats source as long as condition holds emulating a do while loop.
30 * @param condition The condition which determines if the source will be repeated.
31 * @returns An observable sequence which is repeated as long as the condition holds.
32 */
33 doWhile(condition: () => boolean): Observable<T>;
34
35 /**
36 * Expands an observable sequence by recursively invoking selector.
37 *
38 * @param selector Selector function to invoke for each produced element, resulting in another sequence to which the selector will be invoked recursively again.
39 * @param [scheduler] Scheduler on which to perform the expansion. If not provided, this defaults to the current thread scheduler.
40 * @returns An observable sequence containing all the elements produced by the recursive expansion.
41 */
42 expand(selector: (item: T) => Observable<T>, scheduler?: IScheduler): Observable<T>;
43
44 /**
45 * Runs two observable sequences in parallel and combines their last elemenets.
46 *
47 * @param second Second observable sequence or promise.
48 * @param resultSelector Result selector function to invoke with the last elements of both sequences.
49 * @returns An observable sequence with the result of calling the selector function with the last elements of both input sequences.
50 */
51 forkJoin<TSecond, TResult>(second: Observable<TSecond>, resultSelector: (left: T, right: TSecond) => TResult): Observable<TResult>;
52 forkJoin<TSecond, TResult>(second: IPromise<TSecond>, resultSelector: (left: T, right: TSecond) => TResult): Observable<TResult>;
53
54 /**
55 * Comonadic bind operator.
56 * @param selector A transform function to apply to each element.
57 * @param [scheduler] Scheduler used to execute the operation. If not specified, defaults to the ImmediateScheduler.
58 * @returns An observable sequence which results from the comonadic bind operation.
59 */
60 manySelect<TResult>(selector: (item: Observable<T>, index: number, source: Observable<T>) => TResult, scheduler?: IScheduler): Observable<TResult>;
61 }
62
63 interface ObservableStatic {
64 /**
65 * Determines whether an observable collection contains values. There is an alias for this method called 'ifThen' for browsers <IE9
66 *
67 * @example
68 * res = Rx.Observable.if(condition, obs1, obs2);
69 * @param condition The condition which determines if the thenSource or elseSource will be run.
70 * @param thenSource The observable sequence or promise that will be run if the condition function returns true.
71 * @param elseSource The observable sequence or promise that will be run if the condition function returns false.
72 * @returns An observable sequence which is either the thenSource or elseSource.
73 */
74 if<T>(condition: () => boolean, thenSource: Observable<T>, elseSource: Observable<T>): Observable<T>;
75 if<T>(condition: () => boolean, thenSource: Observable<T>, elseSource: IPromise<T>): Observable<T>;
76 if<T>(condition: () => boolean, thenSource: IPromise<T>, elseSource: Observable<T>): Observable<T>;
77 if<T>(condition: () => boolean, thenSource: IPromise<T>, elseSource: IPromise<T>): Observable<T>;
78
79 /**
80 * Determines whether an observable collection contains values. There is an alias for this method called 'ifThen' for browsers <IE9
81 *
82 * @example
83 * res = Rx.Observable.if(condition, obs1, scheduler);
84 * @param condition The condition which determines if the thenSource or empty sequence will be run.
85 * @param thenSource The observable sequence or promise that will be run if the condition function returns true.
86 * @param scheduler Scheduler used to create Rx.Observabe.Empty.
87 * @returns An observable sequence which is either the thenSource or empty sequence.
88 */
89 if<T>(condition: () => boolean, thenSource: Observable<T>, scheduler?: IScheduler): Observable<T>;
90 if<T>(condition: () => boolean, thenSource: IPromise<T>, scheduler?: IScheduler): Observable<T>;
91
92 /**
93 * Determines whether an observable collection contains values. There is an alias for this method called 'ifThen' for browsers <IE9
94 *
95 * @example
96 * res = Rx.Observable.if(condition, obs1, obs2);
97 * @param condition The condition which determines if the thenSource or elseSource will be run.
98 * @param thenSource The observable sequence or promise that will be run if the condition function returns true.
99 * @param elseSource The observable sequence or promise that will be run if the condition function returns false.
100 * @returns An observable sequence which is either the thenSource or elseSource.
101 */
102 ifThen<T>(condition: () => boolean, thenSource: Observable<T>, elseSource: Observable<T>): Observable<T>;
103 ifThen<T>(condition: () => boolean, thenSource: Observable<T>, elseSource: IPromise<T>): Observable<T>;
104 ifThen<T>(condition: () => boolean, thenSource: IPromise<T>, elseSource: Observable<T>): Observable<T>;
105 ifThen<T>(condition: () => boolean, thenSource: IPromise<T>, elseSource: IPromise<T>): Observable<T>;
106
107 /**
108 * Determines whether an observable collection contains values. There is an alias for this method called 'ifThen' for browsers <IE9
109 *
110 * @example
111 * res = Rx.Observable.if(condition, obs1, scheduler);
112 * @param condition The condition which determines if the thenSource or empty sequence will be run.
113 * @param thenSource The observable sequence or promise that will be run if the condition function returns true.
114 * @param scheduler Scheduler used to create Rx.Observabe.Empty.
115 * @returns An observable sequence which is either the thenSource or empty sequence.
116 */
117 ifThen<T>(condition: () => boolean, thenSource: Observable<T>, scheduler?: IScheduler): Observable<T>;
118 ifThen<T>(condition: () => boolean, thenSource: IPromise<T>, scheduler?: IScheduler): Observable<T>;
119
120 /**
121 * Concatenates the observable sequences obtained by running the specified result selector for each element in source.
122 * There is an alias for this method called 'forIn' for browsers <IE9
123 * @param sources An array of values to turn into an observable sequence.
124 * @param resultSelector A function to apply to each item in the sources array to turn it into an observable sequence.
125 * @returns An observable sequence from the concatenated observable sequences.
126 */
127 for<T, TResult>(sources: T[], resultSelector: (item: T) => Observable<TResult>): Observable<TResult>;
128
129 /**
130 * Concatenates the observable sequences obtained by running the specified result selector for each element in source.
131 * There is an alias for this method called 'forIn' for browsers <IE9
132 * @param sources An array of values to turn into an observable sequence.
133 * @param resultSelector A function to apply to each item in the sources array to turn it into an observable sequence.
134 * @returns An observable sequence from the concatenated observable sequences.
135 */
136 forIn<T, TResult>(sources: T[], resultSelector: (item: T) => Observable<TResult>): Observable<TResult>;
137
138 /**
139 * Repeats source as long as condition holds emulating a while loop.
140 * There is an alias for this method called 'whileDo' for browsers <IE9
141 * @param condition The condition which determines if the source will be repeated.
142 * @param source The observable sequence or promise that will be run if the condition function returns true.
143 * @returns An observable sequence which is repeated as long as the condition holds.
144 */
145 while<T>(condition: () => boolean, source: Observable<T>): Observable<T>;
146 while<T>(condition: () => boolean, source: IPromise<T>): Observable<T>;
147
148 /**
149 * Repeats source as long as condition holds emulating a while loop.
150 * There is an alias for this method called 'whileDo' for browsers <IE9
151 * @param condition The condition which determines if the source will be repeated.
152 * @param source The observable sequence or promise that will be run if the condition function returns true.
153 * @returns An observable sequence which is repeated as long as the condition holds.
154 */
155 whileDo<T>(condition: () => boolean, source: Observable<T>): Observable<T>;
156 whileDo<T>(condition: () => boolean, source: IPromise<T>): Observable<T>;
157
158 /**
159 * Uses selector to determine which source in sources to use.
160 * There is an alias 'switchCase' for browsers <IE9.
161 *
162 * @example
163 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, obs0);
164 * @param selector The function which extracts the value for to test in a case statement.
165 * @param sources A object which has keys which correspond to the case statement labels.
166 * @param elseSource The observable sequence or promise that will be run if the sources are not matched.
167 *
168 * @returns An observable sequence which is determined by a case statement.
169 */
170 case<T>(selector: () => string, sources: { [key: string]: Observable<T>; }, elseSource: Observable<T>): Observable<T>;
171 case<T>(selector: () => string, sources: { [key: string]: IPromise<T>; }, elseSource: Observable<T>): Observable<T>;
172 case<T>(selector: () => string, sources: { [key: string]: Observable<T>; }, elseSource: IPromise<T>): Observable<T>;
173 case<T>(selector: () => string, sources: { [key: string]: IPromise<T>; }, elseSource: IPromise<T>): Observable<T>;
174
175 /**
176 * Uses selector to determine which source in sources to use.
177 * There is an alias 'switchCase' for browsers <IE9.
178 *
179 * @example
180 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 });
181 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, scheduler);
182 *
183 * @param selector The function which extracts the value for to test in a case statement.
184 * @param sources A object which has keys which correspond to the case statement labels.
185 * @param scheduler Scheduler used to create Rx.Observabe.Empty.
186 *
187 * @returns An observable sequence which is determined by a case statement.
188 */
189 case<T>(selector: () => string, sources: { [key: string]: Observable<T>; }, scheduler?: IScheduler): Observable<T>;
190 case<T>(selector: () => string, sources: { [key: string]: IPromise<T>; }, scheduler?: IScheduler): Observable<T>;
191
192 /**
193 * Uses selector to determine which source in sources to use.
194 * There is an alias 'switchCase' for browsers <IE9.
195 *
196 * @example
197 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, obs0);
198 * @param selector The function which extracts the value for to test in a case statement.
199 * @param sources A object which has keys which correspond to the case statement labels.
200 * @param elseSource The observable sequence or promise that will be run if the sources are not matched.
201 *
202 * @returns An observable sequence which is determined by a case statement.
203 */
204 case<T>(selector: () => number, sources: { [key: number]: Observable<T>; }, elseSource: Observable<T>): Observable<T>;
205 case<T>(selector: () => number, sources: { [key: number]: IPromise<T>; }, elseSource: Observable<T>): Observable<T>;
206 case<T>(selector: () => number, sources: { [key: number]: Observable<T>; }, elseSource: IPromise<T>): Observable<T>;
207 case<T>(selector: () => number, sources: { [key: number]: IPromise<T>; }, elseSource: IPromise<T>): Observable<T>;
208
209 /**
210 * Uses selector to determine which source in sources to use.
211 * There is an alias 'switchCase' for browsers <IE9.
212 *
213 * @example
214 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 });
215 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, scheduler);
216 *
217 * @param selector The function which extracts the value for to test in a case statement.
218 * @param sources A object which has keys which correspond to the case statement labels.
219 * @param scheduler Scheduler used to create Rx.Observabe.Empty.
220 *
221 * @returns An observable sequence which is determined by a case statement.
222 */
223 case<T>(selector: () => number, sources: { [key: number]: Observable<T>; }, scheduler?: IScheduler): Observable<T>;
224 case<T>(selector: () => number, sources: { [key: number]: IPromise<T>; }, scheduler?: IScheduler): Observable<T>;
225
226 /**
227 * Uses selector to determine which source in sources to use.
228 * There is an alias 'switchCase' for browsers <IE9.
229 *
230 * @example
231 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, obs0);
232 * @param selector The function which extracts the value for to test in a case statement.
233 * @param sources A object which has keys which correspond to the case statement labels.
234 * @param elseSource The observable sequence or promise that will be run if the sources are not matched.
235 *
236 * @returns An observable sequence which is determined by a case statement.
237 */
238 switchCase<T>(selector: () => string, sources: { [key: string]: Observable<T>; }, elseSource: Observable<T>): Observable<T>;
239 switchCase<T>(selector: () => string, sources: { [key: string]: IPromise<T>; }, elseSource: Observable<T>): Observable<T>;
240 switchCase<T>(selector: () => string, sources: { [key: string]: Observable<T>; }, elseSource: IPromise<T>): Observable<T>;
241 switchCase<T>(selector: () => string, sources: { [key: string]: IPromise<T>; }, elseSource: IPromise<T>): Observable<T>;
242
243 /**
244 * Uses selector to determine which source in sources to use.
245 * There is an alias 'switchCase' for browsers <IE9.
246 *
247 * @example
248 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 });
249 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, scheduler);
250 *
251 * @param selector The function which extracts the value for to test in a case statement.
252 * @param sources A object which has keys which correspond to the case statement labels.
253 * @param scheduler Scheduler used to create Rx.Observabe.Empty.
254 *
255 * @returns An observable sequence which is determined by a case statement.
256 */
257 switchCase<T>(selector: () => string, sources: { [key: string]: Observable<T>; }, scheduler?: IScheduler): Observable<T>;
258 switchCase<T>(selector: () => string, sources: { [key: string]: IPromise<T>; }, scheduler?: IScheduler): Observable<T>;
259
260 /**
261 * Uses selector to determine which source in sources to use.
262 * There is an alias 'switchCase' for browsers <IE9.
263 *
264 * @example
265 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, obs0);
266 * @param selector The function which extracts the value for to test in a case statement.
267 * @param sources A object which has keys which correspond to the case statement labels.
268 * @param elseSource The observable sequence or promise that will be run if the sources are not matched.
269 *
270 * @returns An observable sequence which is determined by a case statement.
271 */
272 switchCase<T>(selector: () => number, sources: { [key: number]: Observable<T>; }, elseSource: Observable<T>): Observable<T>;
273 switchCase<T>(selector: () => number, sources: { [key: number]: IPromise<T>; }, elseSource: Observable<T>): Observable<T>;
274 switchCase<T>(selector: () => number, sources: { [key: number]: Observable<T>; }, elseSource: IPromise<T>): Observable<T>;
275 switchCase<T>(selector: () => number, sources: { [key: number]: IPromise<T>; }, elseSource: IPromise<T>): Observable<T>;
276
277 /**
278 * Uses selector to determine which source in sources to use.
279 * There is an alias 'switchCase' for browsers <IE9.
280 *
281 * @example
282 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 });
283 * res = Rx.Observable.case(selector, { '1': obs1, '2': obs2 }, scheduler);
284 *
285 * @param selector The function which extracts the value for to test in a case statement.
286 * @param sources A object which has keys which correspond to the case statement labels.
287 * @param scheduler Scheduler used to create Rx.Observabe.Empty.
288 *
289 * @returns An observable sequence which is determined by a case statement.
290 */
291 switchCase<T>(selector: () => number, sources: { [key: number]: Observable<T>; }, scheduler?: IScheduler): Observable<T>;
292 switchCase<T>(selector: () => number, sources: { [key: number]: IPromise<T>; }, scheduler?: IScheduler): Observable<T>;
293
294 /**
295 * Runs all observable sequences in parallel and collect their last elements.
296 *
297 * @example
298 * res = Rx.Observable.forkJoin([obs1, obs2]);
299 * @param sources Array of source sequences or promises.
300 * @returns An observable sequence with an array collecting the last elements of all the input sequences.
301 */
302 forkJoin<T>(sources: Array<Observable<T>>): Observable<T[]>;
303 forkJoin<T>(sources: Array<IPromise<T>>): Observable<T[]>;
304
305 /**
306 * Runs all observable sequences in parallel and collect their last elements.
307 *
308 * @example
309 * res = Rx.Observable.forkJoin(obs1, obs2, ...);
310 * @param args Source sequences or promises.
311 * @returns An observable sequence with an array collecting the last elements of all the input sequences.
312 */
313 forkJoin<T>(...args: Array<Observable<T>>): Observable<T[]>;
314 forkJoin<T>(...args: Array<IPromise<T>>): Observable<T[]>;
315 }
316}
317
318declare module "rx-lite-experimental" {
319 export = Rx;
320}
321
\No newline at end of file