Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

IndefiniteObservable.d.ts 1.3 KiB

3 lat temu
123456789101112131415161718192021222324252627282930313233
  1. import { Connect, Observable, ObserverOrNext, Subscription } from './types';
  2. /**
  3. * Observable is a standard interface that's useful for modeling multiple,
  4. * asynchronous events.
  5. *
  6. * IndefiniteObservable is a minimalist implementation of a subset of the TC39
  7. * Observable proposal. It is indefinite because it will never call `complete`
  8. * or `error` on the provided observer.
  9. */
  10. export default class IndefiniteObservable<T> implements Observable<T> {
  11. private _connect;
  12. /**
  13. * The provided function should receive an observer and connect that
  14. * observer's `next` method to an event source (for instance,
  15. * `element.addEventListener('click', observer.next)`).
  16. *
  17. * It must return a function that will disconnect the observer from the event
  18. * source.
  19. */
  20. constructor(connect: Connect<T>);
  21. /**
  22. * `subscribe` uses the function supplied to the constructor to connect an
  23. * observer to an event source. Each observer is connected independently:
  24. * each call to `subscribe` calls `connect` with the new observer.
  25. *
  26. * To disconnect the observer from the event source, call `unsubscribe` on the
  27. * returned subscription.
  28. *
  29. * Note: `subscribe` accepts either a function or an object with a
  30. * next method.
  31. */
  32. subscribe(observerOrNext: ObserverOrNext<T>): Subscription;
  33. }