@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.
- package/dist/index.cjs.js +43 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +39 -12
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +43 -12
- package/dist/index.esm5.js.map +1 -1
- package/dist/src/core/event/event_impl.d.ts +4 -1
- package/dist/src/core/project/api.d.ts +4 -1
- package/dist/src/core/project/project_impl.d.ts +5 -0
- package/package.json +7 -7
package/dist/index.cjs.js
CHANGED
|
@@ -638,11 +638,12 @@ var ProjectImpl = /** @class */ (function (_super) {
|
|
|
638
638
|
},
|
|
639
639
|
set: function (newListings) {
|
|
640
640
|
var createdEvents = this._calculateCreatedEvents(newListings);
|
|
641
|
+
var updatedEvents = this._calculateUpdatedEvents(newListings);
|
|
641
642
|
var deletedEvents = this._calculateDeletedEvents(newListings);
|
|
642
643
|
this._listings = __assign({}, newListings);
|
|
643
644
|
this._updateLocales(newListings);
|
|
644
645
|
this._updateEventsChecksum(newListings);
|
|
645
|
-
this._emitListingsEvents(createdEvents, deletedEvents);
|
|
646
|
+
this._emitListingsEvents(createdEvents, updatedEvents, deletedEvents);
|
|
646
647
|
},
|
|
647
648
|
enumerable: false,
|
|
648
649
|
configurable: true
|
|
@@ -660,6 +661,25 @@ var ProjectImpl = /** @class */ (function (_super) {
|
|
|
660
661
|
return !_this._listings.events.some(function (event) { return id === event.id; });
|
|
661
662
|
});
|
|
662
663
|
};
|
|
664
|
+
/**
|
|
665
|
+
* Calculates events that were updated (present in old listings and new,
|
|
666
|
+
* but with different digest)
|
|
667
|
+
*/
|
|
668
|
+
ProjectImpl.prototype._calculateUpdatedEvents = function (newListings) {
|
|
669
|
+
var _this = this;
|
|
670
|
+
if (!this._listings) {
|
|
671
|
+
return [];
|
|
672
|
+
}
|
|
673
|
+
return newListings.events.filter(function (event) {
|
|
674
|
+
// find event data in new listings
|
|
675
|
+
var existingEvent = _this._listings.events.find(function (_a) {
|
|
676
|
+
var id = _a.id;
|
|
677
|
+
return event.id === id;
|
|
678
|
+
});
|
|
679
|
+
// return true if event data is found and digest is different
|
|
680
|
+
return existingEvent && event.digest !== existingEvent.digest;
|
|
681
|
+
});
|
|
682
|
+
};
|
|
663
683
|
/**
|
|
664
684
|
* Calculates events that were deleted (present in old listings but not in new)
|
|
665
685
|
*/
|
|
@@ -694,16 +714,20 @@ var ProjectImpl = /** @class */ (function (_super) {
|
|
|
694
714
|
/**
|
|
695
715
|
* Emits events based on created and deleted events
|
|
696
716
|
*/
|
|
697
|
-
ProjectImpl.prototype._emitListingsEvents = function (createdEvents, deletedEvents) {
|
|
717
|
+
ProjectImpl.prototype._emitListingsEvents = function (createdEvents, updatedEvents, deletedEvents) {
|
|
698
718
|
var hasCreatedEvents = createdEvents.length > 0;
|
|
699
719
|
var hasDeletedEvents = deletedEvents.length > 0;
|
|
700
|
-
var
|
|
720
|
+
var hasUpdatedEvents = updatedEvents.length > 0;
|
|
721
|
+
var hasChanges = hasCreatedEvents || hasDeletedEvents || hasUpdatedEvents;
|
|
701
722
|
if (hasCreatedEvents) {
|
|
702
723
|
this.emit('listings_events_created', createdEvents);
|
|
703
724
|
}
|
|
704
725
|
if (hasDeletedEvents) {
|
|
705
726
|
this.emit('listings_events_deleted', deletedEvents);
|
|
706
727
|
}
|
|
728
|
+
if (hasUpdatedEvents) {
|
|
729
|
+
this.emit('listings_events_updated', updatedEvents);
|
|
730
|
+
}
|
|
707
731
|
if (hasChanges) {
|
|
708
732
|
this.emit('listings');
|
|
709
733
|
}
|
|
@@ -977,9 +1001,13 @@ function onProjectFieldsUpdated(project, callback) {
|
|
|
977
1001
|
return sdkUtil.subscribe(project, 'updated', callback);
|
|
978
1002
|
}
|
|
979
1003
|
/**
|
|
980
|
-
*
|
|
1004
|
+
* Adds an observer that is called when the project listings are updated.
|
|
1005
|
+
*
|
|
1006
|
+
* @deprecated Use {@link onEventAdded()}, {@link onEventUpdated()} and
|
|
1007
|
+
* {@link onEventRemoved()} instead
|
|
981
1008
|
*/
|
|
982
1009
|
function onProjectListingsUpdated(project, callback) {
|
|
1010
|
+
console.warn('onProjectListingsUpdated() is deprecated. Please use onEventAdded(), onEventUpdated() and onEventRemoved() instead');
|
|
983
1011
|
return sdkUtil.subscribe(project, 'listings', callback);
|
|
984
1012
|
}
|
|
985
1013
|
|
|
@@ -1079,11 +1107,12 @@ var EventImpl = /** @class */ (function (_super) {
|
|
|
1079
1107
|
_this._context = context;
|
|
1080
1108
|
_this._state = _this.calculateState();
|
|
1081
1109
|
_this._internalState = _this.calculateInternalState();
|
|
1082
|
-
_this.
|
|
1083
|
-
_this.
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
_this.
|
|
1110
|
+
_this.boundHandleState = _this.handleState.bind(_this);
|
|
1111
|
+
_this.boundHandleInternalState = _this.handleInternalState.bind(_this);
|
|
1112
|
+
_this.boundHandleEventsUpdated = _this.handleEventsUpdated.bind(_this);
|
|
1113
|
+
_this.unsubscribeStateHandler = sdkUtil.onTick(_this.boundHandleState);
|
|
1114
|
+
_this.unsubscribeInternalStateHandler = sdkUtil.onTick(_this.boundHandleInternalState);
|
|
1115
|
+
_this.unsubscribeListingsHandler = sdkUtil.subscribe(_this.context.project, 'listings_events_updated', _this.boundHandleEventsUpdated);
|
|
1087
1116
|
return _this;
|
|
1088
1117
|
}
|
|
1089
1118
|
EventImpl.prototype.calculateState = function () {
|
|
@@ -1127,15 +1156,17 @@ var EventImpl = /** @class */ (function (_super) {
|
|
|
1127
1156
|
this.emit('internal_state', internalState);
|
|
1128
1157
|
}
|
|
1129
1158
|
};
|
|
1130
|
-
EventImpl.prototype.
|
|
1159
|
+
EventImpl.prototype.handleEventsUpdated = function (events) {
|
|
1131
1160
|
var _this = this;
|
|
1132
|
-
var
|
|
1133
|
-
var data = project.events.find(function (_a) {
|
|
1161
|
+
var data = events.find(function (_a) {
|
|
1134
1162
|
var id = _a.id;
|
|
1135
1163
|
return id === _this.id;
|
|
1136
1164
|
});
|
|
1137
1165
|
if (data && this._data.digest !== data.digest) {
|
|
1138
1166
|
this._data = data;
|
|
1167
|
+
// Forcing state recalculation to ensure the event is in the correct state
|
|
1168
|
+
this.handleState();
|
|
1169
|
+
this.handleInternalState();
|
|
1139
1170
|
this.emit('updated');
|
|
1140
1171
|
}
|
|
1141
1172
|
};
|