mergeScan.d.ts 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Operator } from '../Operator';
  2. import { Observable } from '../Observable';
  3. import { Subscriber } from '../Subscriber';
  4. import { Subscription } from '../Subscription';
  5. import { OuterSubscriber } from '../OuterSubscriber';
  6. import { InnerSubscriber } from '../InnerSubscriber';
  7. import { OperatorFunction } from '../interfaces';
  8. /**
  9. * Applies an accumulator function over the source Observable where the
  10. * accumulator function itself returns an Observable, then each intermediate
  11. * Observable returned is merged into the output Observable.
  12. *
  13. * <span class="informal">It's like {@link scan}, but the Observables returned
  14. * by the accumulator are merged into the outer Observable.</span>
  15. *
  16. * @example <caption>Count the number of click events</caption>
  17. * const click$ = Rx.Observable.fromEvent(document, 'click');
  18. * const one$ = click$.mapTo(1);
  19. * const seed = 0;
  20. * const count$ = one$.mergeScan((acc, one) => Rx.Observable.of(acc + one), seed);
  21. * count$.subscribe(x => console.log(x));
  22. *
  23. * // Results:
  24. * 1
  25. * 2
  26. * 3
  27. * 4
  28. * // ...and so on for each click
  29. *
  30. * @param {function(acc: R, value: T): Observable<R>} accumulator
  31. * The accumulator function called on each source value.
  32. * @param seed The initial accumulation value.
  33. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of
  34. * input Observables being subscribed to concurrently.
  35. * @return {Observable<R>} An observable of the accumulated values.
  36. * @method mergeScan
  37. * @owner Observable
  38. */
  39. export declare function mergeScan<T, R>(accumulator: (acc: R, value: T) => Observable<R>, seed: R, concurrent?: number): OperatorFunction<T, R>;
  40. export declare class MergeScanOperator<T, R> implements Operator<T, R> {
  41. private accumulator;
  42. private seed;
  43. private concurrent;
  44. constructor(accumulator: (acc: R, value: T) => Observable<R>, seed: R, concurrent: number);
  45. call(subscriber: Subscriber<R>, source: any): any;
  46. }
  47. /**
  48. * We need this JSDoc comment for affecting ESDoc.
  49. * @ignore
  50. * @extends {Ignored}
  51. */
  52. export declare class MergeScanSubscriber<T, R> extends OuterSubscriber<T, R> {
  53. private accumulator;
  54. private acc;
  55. private concurrent;
  56. private hasValue;
  57. private hasCompleted;
  58. private buffer;
  59. private active;
  60. protected index: number;
  61. constructor(destination: Subscriber<R>, accumulator: (acc: R, value: T) => Observable<R>, acc: R, concurrent: number);
  62. protected _next(value: any): void;
  63. private _innerSub(ish, value, index);
  64. protected _complete(): void;
  65. notifyNext(outerValue: T, innerValue: R, outerIndex: number, innerIndex: number, innerSub: InnerSubscriber<T, R>): void;
  66. notifyComplete(innerSub: Subscription): void;
  67. }