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.

shareReplay.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. if (!subject || hasError) {
  30. hasError = false;
  31. subject = new ReplaySubject_1.ReplaySubject(bufferSize, windowTime, scheduler);
  32. subscription = source.subscribe({
  33. next: function (value) { subject.next(value); },
  34. error: function (err) {
  35. hasError = true;
  36. subject.error(err);
  37. },
  38. complete: function () {
  39. isComplete = true;
  40. subject.complete();
  41. },
  42. });
  43. }
  44. var innerSub = subject.subscribe(this);
  45. this.add(function () {
  46. refCount--;
  47. innerSub.unsubscribe();
  48. if (subscription && !isComplete && useRefCount && refCount === 0) {
  49. subscription.unsubscribe();
  50. subscription = undefined;
  51. subject = undefined;
  52. }
  53. });
  54. };
  55. }
  56. //# sourceMappingURL=shareReplay.js.map