Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

defer.d.ts 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { Observable } from '../Observable';
  2. import { SubscribableOrPromise } from '../types';
  3. /**
  4. * Creates an Observable that, on subscribe, calls an Observable factory to
  5. * make an Observable for each new Observer.
  6. *
  7. * <span class="informal">Creates the Observable lazily, that is, only when it
  8. * is subscribed.
  9. * </span>
  10. *
  11. * ![](defer.png)
  12. *
  13. * `defer` allows you to create the Observable only when the Observer
  14. * subscribes, and create a fresh Observable for each Observer. It waits until
  15. * an Observer subscribes to it, and then it generates an Observable,
  16. * typically with an Observable factory function. It does this afresh for each
  17. * subscriber, so although each subscriber may think it is subscribing to the
  18. * same Observable, in fact each subscriber gets its own individual
  19. * Observable.
  20. *
  21. * ## Example
  22. * ### Subscribe to either an Observable of clicks or an Observable of interval, at random
  23. * ```javascript
  24. * const clicksOrInterval = defer(function () {
  25. * return Math.random() > 0.5
  26. * ? fromEvent(document, 'click')
  27. * : interval(1000);
  28. * });
  29. * clicksOrInterval.subscribe(x => console.log(x));
  30. *
  31. * // Results in the following behavior:
  32. * // If the result of Math.random() is greater than 0.5 it will listen
  33. * // for clicks anywhere on the "document"; when document is clicked it
  34. * // will log a MouseEvent object to the console. If the result is less
  35. * // than 0.5 it will emit ascending numbers, one every second(1000ms).
  36. * ```
  37. *
  38. * @see {@link Observable}
  39. *
  40. * @param {function(): SubscribableOrPromise} observableFactory The Observable
  41. * factory function to invoke for each Observer that subscribes to the output
  42. * Observable. May also return a Promise, which will be converted on the fly
  43. * to an Observable.
  44. * @return {Observable} An Observable whose Observers' subscriptions trigger
  45. * an invocation of the given Observable factory function.
  46. * @static true
  47. * @name defer
  48. * @owner Observable
  49. */
  50. export declare function defer<T>(observableFactory: () => SubscribableOrPromise<T> | void): Observable<T>;