polfan-server-js-client 0.1.995 → 0.1.997

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -650,10 +650,10 @@ function TopicHistoryWindow_toPrimitive(input, hint) { if (TopicHistoryWindow_ty
650
650
 
651
651
  var WindowState;
652
652
  (function (WindowState) {
653
- WindowState[WindowState["EMPTY"] = 0] = "EMPTY";
654
- WindowState[WindowState["LATEST_LIVE"] = 1] = "LATEST_LIVE";
655
- WindowState[WindowState["LATEST_FETCHED"] = 2] = "LATEST_FETCHED";
656
- WindowState[WindowState["PAST_FETCHED"] = 3] = "PAST_FETCHED";
653
+ WindowState[WindowState["LIVE"] = 0] = "LIVE";
654
+ WindowState[WindowState["LATEST"] = 1] = "LATEST";
655
+ WindowState[WindowState["PAST"] = 2] = "PAST";
656
+ WindowState[WindowState["OLDEST"] = 3] = "OLDEST";
657
657
  })(WindowState || (WindowState = {}));
658
658
  var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj) {
659
659
  TopicHistoryWindow_inherits(TraversableRemoteCollection, _ObservableIndexedObj);
@@ -666,7 +666,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
666
666
  }
667
667
  _this = _super.call.apply(_super, [this].concat(args));
668
668
  TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "limit", 50);
669
- TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "currentState", WindowState.EMPTY);
669
+ TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "currentState", WindowState.LIVE);
670
670
  TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "fetchingState", undefined);
671
671
  return _this;
672
672
  }
@@ -694,13 +694,13 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
694
694
  switch (_context.prev = _context.next) {
695
695
  case 0:
696
696
  this.throwIfFetchingInProgress();
697
- if (!(this.currentState === WindowState.LATEST_FETCHED)) {
697
+ if (!(this.currentState === WindowState.LATEST)) {
698
698
  _context.next = 3;
699
699
  break;
700
700
  }
701
701
  return _context.abrupt("return");
702
702
  case 3:
703
- this.fetchingState = WindowState.LATEST_FETCHED;
703
+ this.fetchingState = WindowState.LATEST;
704
704
  _context.prev = 4;
705
705
  _context.next = 7;
706
706
  return this.fetchLatestItems();
@@ -713,7 +713,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
713
713
  case 11:
714
714
  this.deleteAll();
715
715
  this.addItems(result, 'tail');
716
- this.currentState = WindowState.LATEST_FETCHED;
716
+ this.currentState = WindowState.LATEST;
717
717
  case 14:
718
718
  case "end":
719
719
  return _context.stop();
@@ -735,37 +735,46 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
735
735
  while (1) {
736
736
  switch (_context2.prev = _context2.next) {
737
737
  case 0:
738
+ if (!(this.state === WindowState.OLDEST)) {
739
+ _context2.next = 2;
740
+ break;
741
+ }
742
+ return _context2.abrupt("return");
743
+ case 2:
738
744
  this.throwIfFetchingInProgress();
739
- this.fetchingState = WindowState.PAST_FETCHED;
740
- _context2.prev = 2;
741
- _context2.next = 5;
745
+ this.fetchingState = WindowState.PAST;
746
+ _context2.prev = 4;
747
+ _context2.next = 7;
742
748
  return this.fetchItemsBefore();
743
- case 5:
749
+ case 7:
744
750
  result = _context2.sent;
745
- case 6:
746
- _context2.prev = 6;
751
+ case 8:
752
+ _context2.prev = 8;
747
753
  this.fetchingState = undefined;
748
- return _context2.finish(6);
749
- case 9:
754
+ return _context2.finish(8);
755
+ case 11:
750
756
  if (result) {
751
- _context2.next = 11;
757
+ _context2.next = 13;
752
758
  break;
753
759
  }
754
760
  return _context2.abrupt("return", this.resetToLatest());
755
- case 11:
756
- if (!result.length) {
757
- _context2.next = 15;
761
+ case 13:
762
+ if (result.length) {
763
+ _context2.next = 16;
758
764
  break;
759
765
  }
766
+ this.currentState = WindowState.OLDEST;
767
+ return _context2.abrupt("return");
768
+ case 16:
760
769
  this.addItems(result, 'head');
761
- _context2.next = 15;
770
+ _context2.next = 19;
762
771
  return this.refreshFetchedState();
763
- case 15:
772
+ case 19:
764
773
  case "end":
765
774
  return _context2.stop();
766
775
  }
767
776
  }
768
- }, _callee2, this, [[2,, 6, 9]]);
777
+ }, _callee2, this, [[4,, 8, 11]]);
769
778
  }));
770
779
  function fetchPrevious() {
771
780
  return _fetchPrevious.apply(this, arguments);
@@ -782,38 +791,39 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
782
791
  switch (_context3.prev = _context3.next) {
783
792
  case 0:
784
793
  this.throwIfFetchingInProgress();
785
- _context3.prev = 1;
786
- _context3.next = 4;
794
+ this.fetchingState = WindowState.PAST;
795
+ _context3.prev = 2;
796
+ _context3.next = 5;
787
797
  return this.fetchItemsAfter();
788
- case 4:
789
- result = _context3.sent;
790
798
  case 5:
791
- _context3.prev = 5;
799
+ result = _context3.sent;
800
+ case 6:
801
+ _context3.prev = 6;
792
802
  this.fetchingState = undefined;
793
- return _context3.finish(5);
794
- case 8:
803
+ return _context3.finish(6);
804
+ case 9:
795
805
  if (result) {
796
- _context3.next = 12;
806
+ _context3.next = 13;
797
807
  break;
798
808
  }
799
- _context3.next = 11;
809
+ _context3.next = 12;
800
810
  return this.resetToLatest();
801
- case 11:
802
- return _context3.abrupt("return");
803
811
  case 12:
812
+ return _context3.abrupt("return");
813
+ case 13:
804
814
  if (!result.length) {
805
- _context3.next = 16;
815
+ _context3.next = 17;
806
816
  break;
807
817
  }
808
818
  this.addItems(result, 'tail');
809
- _context3.next = 16;
819
+ _context3.next = 17;
810
820
  return this.refreshFetchedState();
811
- case 16:
821
+ case 17:
812
822
  case "end":
813
823
  return _context3.stop();
814
824
  }
815
825
  }
816
- }, _callee3, this, [[1,, 5, 8]]);
826
+ }, _callee3, this, [[2,, 6, 9]]);
817
827
  }));
818
828
  function fetchNext() {
819
829
  return _fetchNext.apply(this, arguments);
@@ -835,11 +845,11 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
835
845
  _context4.next = 6;
836
846
  break;
837
847
  }
838
- _context4.t0 = WindowState.LATEST_FETCHED;
848
+ _context4.t0 = WindowState.LATEST;
839
849
  _context4.next = 7;
840
850
  break;
841
851
  case 6:
842
- _context4.t0 = WindowState.PAST_FETCHED;
852
+ _context4.t0 = WindowState.PAST;
843
853
  case 7:
844
854
  this.currentState = _context4.t0;
845
855
  case 8:
@@ -854,20 +864,6 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
854
864
  }
855
865
  return refreshFetchedState;
856
866
  }()
857
- }, {
858
- key: "refreshLiveState",
859
- value: function refreshLiveState() {
860
- if (this.currentState === WindowState.EMPTY && this.length) {
861
- this.currentState = WindowState.LATEST_LIVE;
862
- }
863
- }
864
- }, {
865
- key: "throwIfFetchingInProgress",
866
- value: function throwIfFetchingInProgress() {
867
- if (this.fetchingState) {
868
- throw new Error("Items fetching in progress: ".concat(WindowState[this.fetchingState]));
869
- }
870
- }
871
867
  }, {
872
868
  key: "addItems",
873
869
  value: function addItems(newItems, to) {
@@ -881,6 +877,13 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
881
877
  this.deleteAll();
882
878
  this.set.apply(this, TopicHistoryWindow_toConsumableArray(result));
883
879
  }
880
+ }, {
881
+ key: "throwIfFetchingInProgress",
882
+ value: function throwIfFetchingInProgress() {
883
+ if (this.fetchingState) {
884
+ throw new Error("Items fetching in progress: ".concat(WindowState[this.fetchingState]));
885
+ }
886
+ }
884
887
 
885
888
  /**
886
889
  * Return array with messages of count that matching limit.
@@ -948,9 +951,8 @@ var TopicHistoryWindow = /*#__PURE__*/function (_TraversableRemoteCol) {
948
951
  while (1) {
949
952
  switch (_context5.prev = _context5.next) {
950
953
  case 0:
951
- if ([WindowState.LATEST_FETCHED, WindowState.LATEST_LIVE, WindowState.EMPTY].includes(this.state) && ev.location.roomId === this.roomId && ev.location.topicId === this.topicId) {
952
- this.set(ev.message);
953
- this.refreshLiveState();
954
+ if ([WindowState.LATEST, WindowState.LIVE].includes(this.state) && ev.location.roomId === this.roomId && ev.location.topicId === this.topicId) {
955
+ this.addItems([ev.message], 'tail');
954
956
  }
955
957
  case 1:
956
958
  case "end":
@@ -2318,7 +2320,7 @@ var RoomsManager = /*#__PURE__*/function () {
2318
2320
  key: "handleNewMessage",
2319
2321
  value: function handleNewMessage(ev) {
2320
2322
  var topics = this.topics.get(ev.location.roomId);
2321
- var topic = topics.get(ev.location.topicId);
2323
+ var topic = topics === null || topics === void 0 ? void 0 : topics.get(ev.location.topicId);
2322
2324
  if (topic) {
2323
2325
  topics.set(RoomsManager_objectSpread(RoomsManager_objectSpread({}, topic), {}, {
2324
2326
  messageCount: topic.messageCount + 1,