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 1.7KB

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