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

shareReplay.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var ReplaySubject_1 = require("../ReplaySubject");
  4. function shareReplay(configOrBufferSize, windowTime, scheduler) {
  5. var config;
  6. if (configOrBufferSize && typeof configOrBufferSize === 'object') {
  7. config = configOrBufferSize;
  8. }
  9. else {
  10. config = {
  11. bufferSize: configOrBufferSize,
  12. windowTime: windowTime,
  13. refCount: false,
  14. scheduler: scheduler
  15. };
  16. }
  17. return function (source) { return source.lift(shareReplayOperator(config)); };
  18. }
  19. exports.shareReplay = shareReplay;
  20. function shareReplayOperator(_a) {
  21. var _b = _a.bufferSize, bufferSize = _b === void 0 ? Number.POSITIVE_INFINITY : _b, _c = _a.windowTime, windowTime = _c === void 0 ? Number.POSITIVE_INFINITY : _c, useRefCount = _a.refCount, scheduler = _a.scheduler;
  22. var subject;
  23. var refCount = 0;
  24. var subscription;
  25. var hasError = false;
  26. var isComplete = false;
  27. return function shareReplayOperation(source) {
  28. refCount++;
  29. var innerSub;
  30. if (!subject || hasError) {
  31. hasError = false;
  32. subject = new ReplaySubject_1.ReplaySubject(bufferSize, windowTime, scheduler);
  33. innerSub = subject.subscribe(this);
  34. subscription = source.subscribe({
  35. next: function (value) { subject.next(value); },
  36. error: function (err) {
  37. hasError = true;
  38. subject.error(err);
  39. },
  40. complete: function () {
  41. isComplete = true;
  42. subscription = undefined;
  43. subject.complete();
  44. },
  45. });
  46. }
  47. else {
  48. innerSub = subject.subscribe(this);
  49. }
  50. this.add(function () {
  51. refCount--;
  52. innerSub.unsubscribe();
  53. if (subscription && !isComplete && useRefCount && refCount === 0) {
  54. subscription.unsubscribe();
  55. subscription = undefined;
  56. subject = undefined;
  57. }
  58. });
  59. };
  60. }
  61. //# sourceMappingURL=shareReplay.js.map