subscribeTo.js 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var subscribeToArray_1 = require("./subscribeToArray");
  4. var subscribeToPromise_1 = require("./subscribeToPromise");
  5. var subscribeToIterable_1 = require("./subscribeToIterable");
  6. var subscribeToObservable_1 = require("./subscribeToObservable");
  7. var isArrayLike_1 = require("./isArrayLike");
  8. var isPromise_1 = require("./isPromise");
  9. var isObject_1 = require("./isObject");
  10. var iterator_1 = require("../symbol/iterator");
  11. var observable_1 = require("../symbol/observable");
  12. exports.subscribeTo = function (result) {
  13. if (!!result && typeof result[observable_1.observable] === 'function') {
  14. return subscribeToObservable_1.subscribeToObservable(result);
  15. }
  16. else if (isArrayLike_1.isArrayLike(result)) {
  17. return subscribeToArray_1.subscribeToArray(result);
  18. }
  19. else if (isPromise_1.isPromise(result)) {
  20. return subscribeToPromise_1.subscribeToPromise(result);
  21. }
  22. else if (!!result && typeof result[iterator_1.iterator] === 'function') {
  23. return subscribeToIterable_1.subscribeToIterable(result);
  24. }
  25. else {
  26. var value = isObject_1.isObject(result) ? 'an invalid object' : "'" + result + "'";
  27. var msg = "You provided " + value + " where a stream was expected."
  28. + ' You can provide an Observable, Promise, Array, or Iterable.';
  29. throw new TypeError(msg);
  30. }
  31. };
  32. //# sourceMappingURL=subscribeTo.js.map