rx.binding.es6.d.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. declare module Rx {
  2. export interface ConnectableObservable<T> extends Observable<T> {
  3. connect(): IDisposable;
  4. refCount(): Observable<T>;
  5. }
  6. export interface Observable<T> {
  7. /**
  8. * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
  9. * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
  10. * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay.
  11. *
  12. * @example
  13. * 1 - res = source.multicast(observable);
  14. * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; });
  15. *
  16. * @param {Function|Subject} subjectOrSubjectSelector
  17. * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function.
  18. * Or:
  19. * Subject to push source elements into.
  20. *
  21. * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if <paramref name="subjectOrSubjectSelector" is a factory function.
  22. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  23. */
  24. multicast(subject: ISubject<T> | (() => ISubject<T>)): ConnectableObservable<T>;
  25. /**
  26. * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
  27. * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
  28. * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay.
  29. *
  30. * @example
  31. * 1 - res = source.multicast(observable);
  32. * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; });
  33. *
  34. * @param {Function|Subject} subjectOrSubjectSelector
  35. * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function.
  36. * Or:
  37. * Subject to push source elements into.
  38. *
  39. * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if <paramref name="subjectOrSubjectSelector" is a factory function.
  40. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  41. */
  42. multicast<TResult>(subjectSelector: ISubject<T> | (() => ISubject<T>), selector: (source: ConnectableObservable<T>) => Observable<T>): Observable<T>;
  43. }
  44. export interface Observable<T> {
  45. /**
  46. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
  47. * This operator is a specialization of Multicast using a regular Subject.
  48. *
  49. * @example
  50. * var resres = source.publish();
  51. * var res = source.publish(function (x) { return x; });
  52. *
  53. * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
  54. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  55. */
  56. publish(): ConnectableObservable<T>;
  57. /**
  58. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
  59. * This operator is a specialization of Multicast using a regular Subject.
  60. *
  61. * @example
  62. * var resres = source.publish();
  63. * var res = source.publish(function (x) { return x; });
  64. *
  65. * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
  66. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  67. */
  68. publish<TResult>(selector: (source: ConnectableObservable<T>) => Observable<TResult>): Observable<TResult>;
  69. }
  70. export interface Observable<T> {
  71. /**
  72. * Returns an observable sequence that shares a single subscription to the underlying sequence.
  73. * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
  74. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
  75. */
  76. share(): Observable<T>;
  77. }
  78. export interface Observable<T> {
  79. /**
  80. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
  81. * This operator is a specialization of Multicast using a AsyncSubject.
  82. *
  83. * @example
  84. * var res = source.publishLast();
  85. * var res = source.publishLast(function (x) { return x; });
  86. *
  87. * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source.
  88. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  89. */
  90. publishLast(): ConnectableObservable<T>;
  91. /**
  92. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
  93. * This operator is a specialization of Multicast using a AsyncSubject.
  94. *
  95. * @example
  96. * var res = source.publishLast();
  97. * var res = source.publishLast(function (x) { return x; });
  98. *
  99. * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source.
  100. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  101. */
  102. publishLast<TResult>(selector: (source: ConnectableObservable<T>) => Observable<TResult>): Observable<TResult>;
  103. }
  104. export interface Observable<T> {
  105. /**
  106. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
  107. * This operator is a specialization of Multicast using a BehaviorSubject.
  108. *
  109. * @example
  110. * var res = source.publishValue(42);
  111. * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
  112. *
  113. * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.
  114. * @param {Mixed} initialValue Initial value received by observers upon subscription.
  115. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  116. */
  117. publishValue(initialValue: T): ConnectableObservable<T>;
  118. /**
  119. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
  120. * This operator is a specialization of Multicast using a BehaviorSubject.
  121. *
  122. * @example
  123. * var res = source.publishValue(42);
  124. * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
  125. *
  126. * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.
  127. * @param {Mixed} initialValue Initial value received by observers upon subscription.
  128. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  129. */
  130. publishValue<TResult>(selector: (source: ConnectableObservable<T>) => Observable<TResult>, initialValue: T): Observable<TResult>;
  131. }
  132. export interface Observable<T> {
  133. /**
  134. * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
  135. * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
  136. * @param {Mixed} initialValue Initial value received by observers upon subscription.
  137. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
  138. */
  139. shareValue(initialValue: T): Observable<T>;
  140. }
  141. export interface Observable<T> {
  142. /**
  143. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
  144. * This operator is a specialization of Multicast using a ReplaySubject.
  145. *
  146. * @example
  147. * var res = source.replay(null, 3);
  148. * var res = source.replay(null, 3, 500);
  149. * var res = source.replay(null, 3, 500, scheduler);
  150. * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
  151. *
  152. * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.
  153. * @param bufferSize [Optional] Maximum element count of the replay buffer.
  154. * @param windowSize [Optional] Maximum time length of the replay buffer.
  155. * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
  156. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  157. */
  158. replay(selector?: void, bufferSize?: number, window?: number, scheduler?: IScheduler): ConnectableObservable<T>; // hack to catch first omitted parameter
  159. /**
  160. * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
  161. * This operator is a specialization of Multicast using a ReplaySubject.
  162. *
  163. * @example
  164. * var res = source.replay(null, 3);
  165. * var res = source.replay(null, 3, 500);
  166. * var res = source.replay(null, 3, 500, scheduler);
  167. * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
  168. *
  169. * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.
  170. * @param bufferSize [Optional] Maximum element count of the replay buffer.
  171. * @param windowSize [Optional] Maximum time length of the replay buffer.
  172. * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
  173. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
  174. */
  175. replay(selector: (source: ConnectableObservable<T>) => Observable<T>, bufferSize?: number, window?: number, scheduler?: IScheduler): Observable<T>;
  176. }
  177. export interface Observable<T> {
  178. /**
  179. * Returns an observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
  180. * This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
  181. *
  182. * @example
  183. * var res = source.shareReplay(3);
  184. * var res = source.shareReplay(3, 500);
  185. * var res = source.shareReplay(3, 500, scheduler);
  186. *
  187. * @param bufferSize [Optional] Maximum element count of the replay buffer.
  188. * @param window [Optional] Maximum time length of the replay buffer.
  189. * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
  190. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
  191. */
  192. shareReplay(bufferSize?: number, window?: number, scheduler?: IScheduler): Observable<T>;
  193. }
  194. export interface BehaviorSubject<T> extends Subject<T> {
  195. /**
  196. * Gets the current value or throws an exception.
  197. * Value is frozen after onCompleted is called.
  198. * After onError is called always throws the specified exception.
  199. * An exception is always thrown after dispose is called.
  200. * @returns {Mixed} The initial value passed to the constructor until onNext is called; after which, the last value passed to onNext.
  201. */
  202. getValue(): T;
  203. }
  204. interface BehaviorSubjectStatic {
  205. /**
  206. * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
  207. * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
  208. */
  209. new <T>(initialValue: T): BehaviorSubject<T>;
  210. }
  211. /**
  212. * Represents a value that changes over time.
  213. * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
  214. */
  215. export var BehaviorSubject: BehaviorSubjectStatic;
  216. export interface ReplaySubject<T> extends Subject<T> { }
  217. interface ReplaySubjectStatic {
  218. /**
  219. * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
  220. * @param {Number} [bufferSize] Maximum element count of the replay buffer.
  221. * @param {Number} [windowSize] Maximum time length of the replay buffer.
  222. * @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
  223. */
  224. new <T>(bufferSize?: number, window?: number, scheduler?: IScheduler): ReplaySubject<T>;
  225. }
  226. /**
  227. * Represents an object that is both an observable sequence as well as an observer.
  228. * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
  229. */
  230. export var ReplaySubject: ReplaySubjectStatic;
  231. export interface Observable<T> {
  232. /**
  233. * Returns an observable sequence that shares a single subscription to the underlying sequence. This observable sequence
  234. * can be resubscribed to, even if all prior subscriptions have ended. (unlike `.publish().refCount()`)
  235. * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source.
  236. */
  237. singleInstance(): Observable<T>;
  238. }
  239. }
  240. declare module "rx.binding" { export = Rx; }