Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

fetch.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var __rest = (this && this.__rest) || function (s, e) {
  14. var t = {};
  15. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  16. t[p] = s[p];
  17. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  18. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
  19. t[p[i]] = s[p[i]];
  20. return t;
  21. };
  22. Object.defineProperty(exports, "__esModule", { value: true });
  23. var Observable_1 = require("../../Observable");
  24. var Subscription_1 = require("../../Subscription");
  25. var from_1 = require("../../observable/from");
  26. function fromFetch(input, initWithSelector) {
  27. if (initWithSelector === void 0) { initWithSelector = {}; }
  28. var selector = initWithSelector.selector, init = __rest(initWithSelector, ["selector"]);
  29. return new Observable_1.Observable(function (subscriber) {
  30. var controller = new AbortController();
  31. var signal = controller.signal;
  32. var abortable = true;
  33. var unsubscribed = false;
  34. var subscription = new Subscription_1.Subscription();
  35. subscription.add(function () {
  36. unsubscribed = true;
  37. if (abortable) {
  38. controller.abort();
  39. }
  40. });
  41. var perSubscriberInit;
  42. if (init) {
  43. if (init.signal) {
  44. if (init.signal.aborted) {
  45. controller.abort();
  46. }
  47. else {
  48. var outerSignal_1 = init.signal;
  49. var outerSignalHandler_1 = function () {
  50. if (!signal.aborted) {
  51. controller.abort();
  52. }
  53. };
  54. outerSignal_1.addEventListener('abort', outerSignalHandler_1);
  55. subscription.add(function () { return outerSignal_1.removeEventListener('abort', outerSignalHandler_1); });
  56. }
  57. }
  58. perSubscriberInit = __assign({}, init, { signal: signal });
  59. }
  60. else {
  61. perSubscriberInit = { signal: signal };
  62. }
  63. fetch(input, perSubscriberInit).then(function (response) {
  64. if (selector) {
  65. subscription.add(from_1.from(selector(response)).subscribe(function (value) { return subscriber.next(value); }, function (err) {
  66. abortable = false;
  67. if (!unsubscribed) {
  68. subscriber.error(err);
  69. }
  70. }, function () {
  71. abortable = false;
  72. subscriber.complete();
  73. }));
  74. }
  75. else {
  76. abortable = false;
  77. subscriber.next(response);
  78. subscriber.complete();
  79. }
  80. }).catch(function (err) {
  81. abortable = false;
  82. if (!unsubscribed) {
  83. subscriber.error(err);
  84. }
  85. });
  86. return subscription;
  87. });
  88. }
  89. exports.fromFetch = fromFetch;
  90. //# sourceMappingURL=fetch.js.map