rx.lite.extras.es6.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. declare module Rx {
  2. export interface Observer<T> {
  3. /**
  4. * Creates a notification callback from an observer.
  5. * @returns The action that forwards its input notification to the underlying observer.
  6. */
  7. toNotifier(): (notification: Notification<T>) => void;
  8. /**
  9. * Hides the identity of an observer.
  10. * @returns An observer that hides the identity of the specified observer.
  11. */
  12. asObserver(): Observer<T>;
  13. /**
  14. * Checks access to the observer for grammar violations. This includes checking for multiple OnError or OnCompleted calls, as well as reentrancy in any of the observer methods.
  15. * If a violation is detected, an Error is thrown from the offending observer method call.
  16. * @returns An observer that checks callbacks invocations against the observer grammar and, if the checks pass, forwards those to the specified observer.
  17. */
  18. checked(): CheckedObserver<T>;
  19. /**
  20. * Schedules the invocation of observer methods on the given scheduler.
  21. * @param {Scheduler} scheduler Scheduler to schedule observer messages on.
  22. * @returns {Observer} Observer whose messages are scheduled on the given scheduler.
  23. */
  24. notifyOn(scheduler: IScheduler): Observer<T>;
  25. }
  26. export interface ObserverStatic {
  27. /**
  28. * Creates an observer from a notification callback.
  29. *
  30. * @static
  31. * @memberOf Observer
  32. * @param {Function} handler Action that handles a notification.
  33. * @returns The observer object that invokes the specified handler using a notification corresponding to each message it receives.
  34. */
  35. fromNotifier<T>(handler: (notification: Notification<T>, thisArg?: any) => void): Observer<T>;
  36. }
  37. export interface Observable<T> {
  38. /**
  39. * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
  40. *
  41. * This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects
  42. * that require to be run on a scheduler, use subscribeOn.
  43. *
  44. * @param {Scheduler} scheduler Scheduler to notify observers on.
  45. * @returns {Observable} The source sequence whose observations happen on the specified scheduler.
  46. */
  47. observeOn(scheduler: IScheduler): Observable<T>;
  48. }
  49. export interface Observable<T> {
  50. /**
  51. * Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;
  52. * see the remarks section for more information on the distinction between subscribeOn and observeOn.
  53. * This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer
  54. * callbacks on a scheduler, use observeOn.
  55. * @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on.
  56. * @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
  57. */
  58. subscribeOn(scheduler: IScheduler): Observable<T>;
  59. }
  60. export interface ObservableStatic {
  61. /**
  62. * Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
  63. *
  64. * @example
  65. * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; });
  66. * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout);
  67. * @param {Mixed} initialState Initial state.
  68. * @param {Function} condition Condition to terminate generation (upon returning false).
  69. * @param {Function} iterate Iteration step function.
  70. * @param {Function} resultSelector Selector function for results produced in the sequence.
  71. * @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.
  72. * @returns {Observable} The generated sequence.
  73. */
  74. generate<TState, TResult>(initialState: TState, condition: (state: TState) => boolean, iterate: (state: TState) => TState, resultSelector: (state: TState) => TResult, scheduler?: IScheduler): Observable<TResult>;
  75. }
  76. export interface ObservableStatic {
  77. /**
  78. * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
  79. * @param {Function} resourceFactory Factory function to obtain a resource object.
  80. * @param {Function} observableFactory Factory function to obtain an observable sequence that depends on the obtained resource.
  81. * @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object.
  82. */
  83. using<TSource, TResource extends IDisposable>(resourceFactory: () => TResource, observableFactory: (resource: TResource) => Observable<TSource>): Observable<TSource>;
  84. }
  85. export interface Observable<T> {
  86. /**
  87. * Propagates the observable sequence or Promise that reacts first.
  88. * @param {Observable} rightSource Second observable sequence or Promise.
  89. * @returns {Observable} {Observable} An observable sequence that surfaces either of the given sequences, whichever reacted first.
  90. */
  91. amb(observable: ObservableOrPromise<T>): Observable<T>;
  92. }
  93. export interface ObservableStatic {
  94. /**
  95. * Propagates the observable sequence or Promise that reacts first.
  96. * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first.
  97. */
  98. amb<T>(observables: ObservableOrPromise<T>[]): Observable<T>;
  99. /**
  100. * Propagates the observable sequence or Promise that reacts first.
  101. * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first.
  102. */
  103. amb<T>(...observables: ObservableOrPromise<T>[]): Observable<T>;
  104. }
  105. export interface Observable<T> {
  106. /**
  107. * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
  108. * @param {Observable} second Second observable sequence used to produce results after the first sequence terminates.
  109. * @returns {Observable} An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.
  110. */
  111. onErrorResumeNext(second: ObservableOrPromise<T>): Observable<T>;
  112. }
  113. export interface ObservableStatic {
  114. /**
  115. * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
  116. *
  117. * @example
  118. * 1 - res = Rx.Observable.onErrorResumeNext(xs, ys, zs);
  119. * 1 - res = Rx.Observable.onErrorResumeNext([xs, ys, zs]);
  120. * @returns {Observable} An observable sequence that concatenates the source sequences, even if a sequence terminates exceptionally.
  121. */
  122. onErrorResumeNext<T>(...sources: ObservableOrPromise<T>[]): Observable<T>;
  123. /**
  124. * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
  125. *
  126. * @example
  127. * 1 - res = Rx.Observable.onErrorResumeNext(xs, ys, zs);
  128. * 1 - res = Rx.Observable.onErrorResumeNext([xs, ys, zs]);
  129. * @returns {Observable} An observable sequence that concatenates the source sequences, even if a sequence terminates exceptionally.
  130. */
  131. onErrorResumeNext<T>(sources: ObservableOrPromise<T>[]): Observable<T>;
  132. }
  133. export interface Observable<T> {
  134. /**
  135. * Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.
  136. * @param {Number} count Length of each buffer.
  137. * @param {Number} [skip] Number of elements to skip between creation of consecutive buffers. If not provided, defaults to the count.
  138. * @returns {Observable} An observable sequence of buffers.
  139. */
  140. bufferWithCount(count: number, skip?: number): Observable<T[]>;
  141. }
  142. export interface Observable<T> {
  143. /**
  144. * Projects each element of an observable sequence into zero or more windows which are produced based on element count information.
  145. *
  146. * var res = xs.windowWithCount(10);
  147. * var res = xs.windowWithCount(10, 1);
  148. * @param {Number} count Length of each window.
  149. * @param {Number} [skip] Number of elements to skip between creation of consecutive windows. If not specified, defaults to the count.
  150. * @returns {Observable} An observable sequence of windows.
  151. */
  152. windowWithCount(count: number, skip?: number): Observable<Observable<T>>;
  153. }
  154. export interface Observable<T> {
  155. /**
  156. * Returns an array with the specified number of contiguous elements from the end of an observable sequence.
  157. *
  158. * @description
  159. * This operator accumulates a buffer with a length enough to store count elements. Upon completion of the
  160. * source sequence, this buffer is produced on the result sequence.
  161. * @param {Number} count Number of elements to take from the end of the source sequence.
  162. * @returns {Observable} An observable sequence containing a single array with the specified number of elements from the end of the source sequence.
  163. */
  164. takeLastBuffer(count: number): Observable<T[]>;
  165. }
  166. export interface Observable<T> {
  167. /**
  168. * Returns the elements of the specified sequence or the specified value in a singleton sequence if the sequence is empty.
  169. *
  170. * var res = obs = xs.defaultIfEmpty();
  171. * 2 - obs = xs.defaultIfEmpty(false);
  172. *
  173. * @memberOf Observable#
  174. * @param defaultValue The value to return if the sequence is empty. If not provided, this defaults to null.
  175. * @returns {Observable} An observable sequence that contains the specified default value if the source is empty; otherwise, the elements of the source itself.
  176. */
  177. defaultIfEmpty(defaultValue?: T): Observable<T>;
  178. }
  179. export interface Observable<T> {
  180. /**
  181. * Returns an observable sequence that contains only distinct elements according to the keySelector and the comparer.
  182. * Usage of this operator should be considered carefully due to the maintenance of an internal lookup structure which can grow large.
  183. *
  184. * @example
  185. * var res = obs = xs.distinct();
  186. * 2 - obs = xs.distinct(function (x) { return x.id; });
  187. * 2 - obs = xs.distinct(function (x) { return x.id; }, function (a,b) { return a === b; });
  188. * @param {Function} [keySelector] A function to compute the comparison key for each element.
  189. * @param {Function} [comparer] Used to compare items in the collection.
  190. * @returns {Observable} An observable sequence only containing the distinct elements, based on a computed key value, from the source sequence.
  191. */
  192. distinct<TKey>(keySelector?: (value: T) => TKey, keySerializer?: (key: TKey) => string): Observable<T>;
  193. }
  194. export interface Observable<T> {
  195. /**
  196. * Returns an observable sequence that shares a single subscription to the underlying sequence. This observable sequence
  197. * can be resubscribed to, even if all prior subscriptions have ended. (unlike `.publish().refCount()`)
  198. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source.
  199. */
  200. singleInstance(): Observable<T>;
  201. }
  202. }
  203. declare module "rx.lite.extras" { export = Rx; }