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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /** PURE_IMPORTS_START _ReplaySubject PURE_IMPORTS_END */
  2. import { ReplaySubject } from '../ReplaySubject';
  3. export function shareReplay(configOrBufferSize, windowTime, scheduler) {
  4. var config;
  5. if (configOrBufferSize && typeof configOrBufferSize === 'object') {
  6. config = configOrBufferSize;
  7. }
  8. else {
  9. config = {
  10. bufferSize: configOrBufferSize,
  11. windowTime: windowTime,
  12. refCount: false,
  13. scheduler: scheduler
  14. };
  15. }
  16. return function (source) { return source.lift(shareReplayOperator(config)); };
  17. }
  18. function shareReplayOperator(_a) {
  19. 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;
  20. var subject;
  21. var refCount = 0;
  22. var subscription;
  23. var hasError = false;
  24. var isComplete = false;
  25. return function shareReplayOperation(source) {
  26. refCount++;
  27. if (!subject || hasError) {
  28. hasError = false;
  29. subject = new ReplaySubject(bufferSize, windowTime, scheduler);
  30. subscription = source.subscribe({
  31. next: function (value) { subject.next(value); },
  32. error: function (err) {
  33. hasError = true;
  34. subject.error(err);
  35. },
  36. complete: function () {
  37. isComplete = true;
  38. subject.complete();
  39. },
  40. });
  41. }
  42. var innerSub = subject.subscribe(this);
  43. this.add(function () {
  44. refCount--;
  45. innerSub.unsubscribe();
  46. if (subscription && !isComplete && useRefCount && refCount === 0) {
  47. subscription.unsubscribe();
  48. subscription = undefined;
  49. subject = undefined;
  50. }
  51. });
  52. };
  53. }
  54. //# sourceMappingURL=shareReplay.js.map