@monterosa/sdk-interact-kit 0.18.5-rc.2 → 0.18.5-rc.3

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.
@@ -634,11 +634,12 @@ var ProjectImpl = /** @class */ (function (_super) {
634
634
  },
635
635
  set: function (newListings) {
636
636
  var createdEvents = this._calculateCreatedEvents(newListings);
637
+ var updatedEvents = this._calculateUpdatedEvents(newListings);
637
638
  var deletedEvents = this._calculateDeletedEvents(newListings);
638
639
  this._listings = __assign({}, newListings);
639
640
  this._updateLocales(newListings);
640
641
  this._updateEventsChecksum(newListings);
641
- this._emitListingsEvents(createdEvents, deletedEvents);
642
+ this._emitListingsEvents(createdEvents, updatedEvents, deletedEvents);
642
643
  },
643
644
  enumerable: false,
644
645
  configurable: true
@@ -656,6 +657,25 @@ var ProjectImpl = /** @class */ (function (_super) {
656
657
  return !_this._listings.events.some(function (event) { return id === event.id; });
657
658
  });
658
659
  };
660
+ /**
661
+ * Calculates events that were updated (present in old listings and new,
662
+ * but with different digest)
663
+ */
664
+ ProjectImpl.prototype._calculateUpdatedEvents = function (newListings) {
665
+ var _this = this;
666
+ if (!this._listings) {
667
+ return [];
668
+ }
669
+ return newListings.events.filter(function (event) {
670
+ // find event data in new listings
671
+ var existingEvent = _this._listings.events.find(function (_a) {
672
+ var id = _a.id;
673
+ return event.id === id;
674
+ });
675
+ // return true if event data is found and digest is different
676
+ return existingEvent && event.digest !== existingEvent.digest;
677
+ });
678
+ };
659
679
  /**
660
680
  * Calculates events that were deleted (present in old listings but not in new)
661
681
  */
@@ -690,16 +710,20 @@ var ProjectImpl = /** @class */ (function (_super) {
690
710
  /**
691
711
  * Emits events based on created and deleted events
692
712
  */
693
- ProjectImpl.prototype._emitListingsEvents = function (createdEvents, deletedEvents) {
713
+ ProjectImpl.prototype._emitListingsEvents = function (createdEvents, updatedEvents, deletedEvents) {
694
714
  var hasCreatedEvents = createdEvents.length > 0;
695
715
  var hasDeletedEvents = deletedEvents.length > 0;
696
- var hasChanges = hasCreatedEvents || hasDeletedEvents;
716
+ var hasUpdatedEvents = updatedEvents.length > 0;
717
+ var hasChanges = hasCreatedEvents || hasDeletedEvents || hasUpdatedEvents;
697
718
  if (hasCreatedEvents) {
698
719
  this.emit('listings_events_created', createdEvents);
699
720
  }
700
721
  if (hasDeletedEvents) {
701
722
  this.emit('listings_events_deleted', deletedEvents);
702
723
  }
724
+ if (hasUpdatedEvents) {
725
+ this.emit('listings_events_updated', updatedEvents);
726
+ }
703
727
  if (hasChanges) {
704
728
  this.emit('listings');
705
729
  }
@@ -973,9 +997,13 @@ function onProjectFieldsUpdated(project, callback) {
973
997
  return subscribe$2(project, 'updated', callback);
974
998
  }
975
999
  /**
976
- * @internal
1000
+ * Adds an observer that is called when the project listings are updated.
1001
+ *
1002
+ * @deprecated Use {@link onEventAdded()}, {@link onEventUpdated()} and
1003
+ * {@link onEventRemoved()} instead
977
1004
  */
978
1005
  function onProjectListingsUpdated(project, callback) {
1006
+ console.warn('onProjectListingsUpdated() is deprecated. Please use onEventAdded(), onEventUpdated() and onEventRemoved() instead');
979
1007
  return subscribe$2(project, 'listings', callback);
980
1008
  }
981
1009
 
@@ -1075,11 +1103,12 @@ var EventImpl = /** @class */ (function (_super) {
1075
1103
  _this._context = context;
1076
1104
  _this._state = _this.calculateState();
1077
1105
  _this._internalState = _this.calculateInternalState();
1078
- _this.unsubscribeStateHandler = onTick(function () { return _this.handleState(); });
1079
- _this.unsubscribeInternalStateHandler = onTick(function () {
1080
- _this.handleInternalState();
1081
- });
1082
- _this.unsubscribeListingsHandler = onProjectListingsUpdated(context.project, function () { return _this.handleListings(); });
1106
+ _this.boundHandleState = _this.handleState.bind(_this);
1107
+ _this.boundHandleInternalState = _this.handleInternalState.bind(_this);
1108
+ _this.boundHandleEventsUpdated = _this.handleEventsUpdated.bind(_this);
1109
+ _this.unsubscribeStateHandler = onTick(_this.boundHandleState);
1110
+ _this.unsubscribeInternalStateHandler = onTick(_this.boundHandleInternalState);
1111
+ _this.unsubscribeListingsHandler = subscribe$2(_this.context.project, 'listings_events_updated', _this.boundHandleEventsUpdated);
1083
1112
  return _this;
1084
1113
  }
1085
1114
  EventImpl.prototype.calculateState = function () {
@@ -1123,15 +1152,17 @@ var EventImpl = /** @class */ (function (_super) {
1123
1152
  this.emit('internal_state', internalState);
1124
1153
  }
1125
1154
  };
1126
- EventImpl.prototype.handleListings = function () {
1155
+ EventImpl.prototype.handleEventsUpdated = function (events) {
1127
1156
  var _this = this;
1128
- var project = this.context.project;
1129
- var data = project.events.find(function (_a) {
1157
+ var data = events.find(function (_a) {
1130
1158
  var id = _a.id;
1131
1159
  return id === _this.id;
1132
1160
  });
1133
1161
  if (data && this._data.digest !== data.digest) {
1134
1162
  this._data = data;
1163
+ // Forcing state recalculation to ensure the event is in the correct state
1164
+ this.handleState();
1165
+ this.handleInternalState();
1135
1166
  this.emit('updated');
1136
1167
  }
1137
1168
  };