EmptyObservable.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { IScheduler } from '../Scheduler';
  2. import { Subscriber } from '../Subscriber';
  3. import { Observable } from '../Observable';
  4. import { TeardownLogic } from '../Subscription';
  5. export interface DispatchArg<T> {
  6. subscriber: Subscriber<T>;
  7. }
  8. /**
  9. * We need this JSDoc comment for affecting ESDoc.
  10. * @extends {Ignored}
  11. * @hide true
  12. */
  13. export declare class EmptyObservable<T> extends Observable<T> {
  14. private scheduler;
  15. /**
  16. * Creates an Observable that emits no items to the Observer and immediately
  17. * emits a complete notification.
  18. *
  19. * <span class="informal">Just emits 'complete', and nothing else.
  20. * </span>
  21. *
  22. * <img src="./img/empty.png" width="100%">
  23. *
  24. * This static operator is useful for creating a simple Observable that only
  25. * emits the complete notification. It can be used for composing with other
  26. * Observables, such as in a {@link mergeMap}.
  27. *
  28. * @example <caption>Emit the number 7, then complete.</caption>
  29. * var result = Rx.Observable.empty().startWith(7);
  30. * result.subscribe(x => console.log(x));
  31. *
  32. * @example <caption>Map and flatten only odd numbers to the sequence 'a', 'b', 'c'</caption>
  33. * var interval = Rx.Observable.interval(1000);
  34. * var result = interval.mergeMap(x =>
  35. * x % 2 === 1 ? Rx.Observable.of('a', 'b', 'c') : Rx.Observable.empty()
  36. * );
  37. * result.subscribe(x => console.log(x));
  38. *
  39. * // Results in the following to the console:
  40. * // x is equal to the count on the interval eg(0,1,2,3,...)
  41. * // x will occur every 1000ms
  42. * // if x % 2 is equal to 1 print abc
  43. * // if x % 2 is not equal to 1 nothing will be output
  44. *
  45. * @see {@link create}
  46. * @see {@link never}
  47. * @see {@link of}
  48. * @see {@link throw}
  49. *
  50. * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
  51. * the emission of the complete notification.
  52. * @return {Observable} An "empty" Observable: emits only the complete
  53. * notification.
  54. * @static true
  55. * @name empty
  56. * @owner Observable
  57. */
  58. static create<T>(scheduler?: IScheduler): Observable<T>;
  59. static dispatch<T>(arg: DispatchArg<T>): void;
  60. constructor(scheduler?: IScheduler);
  61. /** @deprecated internal use only */ _subscribe(subscriber: Subscriber<T>): TeardownLogic;
  62. }