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.

subscribeTo.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Observable } from '../Observable';
  2. import { subscribeToArray } from './subscribeToArray';
  3. import { subscribeToPromise } from './subscribeToPromise';
  4. import { subscribeToIterable } from './subscribeToIterable';
  5. import { subscribeToObservable } from './subscribeToObservable';
  6. import { isArrayLike } from './isArrayLike';
  7. import { isPromise } from './isPromise';
  8. import { isObject } from './isObject';
  9. import { iterator as Symbol_iterator } from '../symbol/iterator';
  10. import { observable as Symbol_observable } from '../symbol/observable';
  11. export const subscribeTo = (result) => {
  12. if (result instanceof Observable) {
  13. return (subscriber) => {
  14. if (result._isScalar) {
  15. subscriber.next(result.value);
  16. subscriber.complete();
  17. return undefined;
  18. }
  19. else {
  20. return result.subscribe(subscriber);
  21. }
  22. };
  23. }
  24. else if (result && typeof result[Symbol_observable] === 'function') {
  25. return subscribeToObservable(result);
  26. }
  27. else if (isArrayLike(result)) {
  28. return subscribeToArray(result);
  29. }
  30. else if (isPromise(result)) {
  31. return subscribeToPromise(result);
  32. }
  33. else if (result && typeof result[Symbol_iterator] === 'function') {
  34. return subscribeToIterable(result);
  35. }
  36. else {
  37. const value = isObject(result) ? 'an invalid object' : `'${result}'`;
  38. const msg = `You provided ${value} where a stream was expected.`
  39. + ' You can provide an Observable, Promise, Array, or Iterable.';
  40. throw new TypeError(msg);
  41. }
  42. };
  43. //# sourceMappingURL=subscribeTo.js.map