Front end of the Slack clone application.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /** PURE_IMPORTS_START ._Subject,._scheduler_queue,._Subscription,._operators_observeOn,._util_ObjectUnsubscribedError,._SubjectSubscription PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { Subject } from './Subject';
  10. import { queue } from './scheduler/queue';
  11. import { Subscription } from './Subscription';
  12. import { ObserveOnSubscriber } from './operators/observeOn';
  13. import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';
  14. import { SubjectSubscription } from './SubjectSubscription';
  15. /**
  16. * @class ReplaySubject<T>
  17. */
  18. export var ReplaySubject = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  19. __extends(ReplaySubject, _super);
  20. function ReplaySubject(bufferSize, windowTime, scheduler) {
  21. if (bufferSize === void 0) {
  22. bufferSize = Number.POSITIVE_INFINITY;
  23. }
  24. if (windowTime === void 0) {
  25. windowTime = Number.POSITIVE_INFINITY;
  26. }
  27. _super.call(this);
  28. this.scheduler = scheduler;
  29. this._events = [];
  30. this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
  31. this._windowTime = windowTime < 1 ? 1 : windowTime;
  32. }
  33. ReplaySubject.prototype.next = function (value) {
  34. var now = this._getNow();
  35. this._events.push(new ReplayEvent(now, value));
  36. this._trimBufferThenGetEvents();
  37. _super.prototype.next.call(this, value);
  38. };
  39. /** @deprecated internal use only */ ReplaySubject.prototype._subscribe = function (subscriber) {
  40. var _events = this._trimBufferThenGetEvents();
  41. var scheduler = this.scheduler;
  42. var subscription;
  43. if (this.closed) {
  44. throw new ObjectUnsubscribedError();
  45. }
  46. else if (this.hasError) {
  47. subscription = Subscription.EMPTY;
  48. }
  49. else if (this.isStopped) {
  50. subscription = Subscription.EMPTY;
  51. }
  52. else {
  53. this.observers.push(subscriber);
  54. subscription = new SubjectSubscription(this, subscriber);
  55. }
  56. if (scheduler) {
  57. subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
  58. }
  59. var len = _events.length;
  60. for (var i = 0; i < len && !subscriber.closed; i++) {
  61. subscriber.next(_events[i].value);
  62. }
  63. if (this.hasError) {
  64. subscriber.error(this.thrownError);
  65. }
  66. else if (this.isStopped) {
  67. subscriber.complete();
  68. }
  69. return subscription;
  70. };
  71. ReplaySubject.prototype._getNow = function () {
  72. return (this.scheduler || queue).now();
  73. };
  74. ReplaySubject.prototype._trimBufferThenGetEvents = function () {
  75. var now = this._getNow();
  76. var _bufferSize = this._bufferSize;
  77. var _windowTime = this._windowTime;
  78. var _events = this._events;
  79. var eventsCount = _events.length;
  80. var spliceCount = 0;
  81. // Trim events that fall out of the time window.
  82. // Start at the front of the list. Break early once
  83. // we encounter an event that falls within the window.
  84. while (spliceCount < eventsCount) {
  85. if ((now - _events[spliceCount].time) < _windowTime) {
  86. break;
  87. }
  88. spliceCount++;
  89. }
  90. if (eventsCount > _bufferSize) {
  91. spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
  92. }
  93. if (spliceCount > 0) {
  94. _events.splice(0, spliceCount);
  95. }
  96. return _events;
  97. };
  98. return ReplaySubject;
  99. }(Subject));
  100. var ReplayEvent = /*@__PURE__*/ (/*@__PURE__*/ function () {
  101. function ReplayEvent(time, value) {
  102. this.time = time;
  103. this.value = value;
  104. }
  105. return ReplayEvent;
  106. }());
  107. //# sourceMappingURL=ReplaySubject.js.map