@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.esm2017.js
CHANGED
|
@@ -420,11 +420,12 @@ class ProjectImpl extends Emitter {
|
|
|
420
420
|
}
|
|
421
421
|
set listings(newListings) {
|
|
422
422
|
const createdEvents = this._calculateCreatedEvents(newListings);
|
|
423
|
+
const updatedEvents = this._calculateUpdatedEvents(newListings);
|
|
423
424
|
const deletedEvents = this._calculateDeletedEvents(newListings);
|
|
424
425
|
this._listings = Object.assign({}, newListings);
|
|
425
426
|
this._updateLocales(newListings);
|
|
426
427
|
this._updateEventsChecksum(newListings);
|
|
427
|
-
this._emitListingsEvents(createdEvents, deletedEvents);
|
|
428
|
+
this._emitListingsEvents(createdEvents, updatedEvents, deletedEvents);
|
|
428
429
|
}
|
|
429
430
|
/**
|
|
430
431
|
* Calculates events that were created (present in new listings but not in old)
|
|
@@ -435,6 +436,21 @@ class ProjectImpl extends Emitter {
|
|
|
435
436
|
}
|
|
436
437
|
return newListings.events.filter(({ id }) => !this._listings.events.some((event) => id === event.id));
|
|
437
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Calculates events that were updated (present in old listings and new,
|
|
441
|
+
* but with different digest)
|
|
442
|
+
*/
|
|
443
|
+
_calculateUpdatedEvents(newListings) {
|
|
444
|
+
if (!this._listings) {
|
|
445
|
+
return [];
|
|
446
|
+
}
|
|
447
|
+
return newListings.events.filter((event) => {
|
|
448
|
+
// find event data in new listings
|
|
449
|
+
const existingEvent = this._listings.events.find(({ id }) => event.id === id);
|
|
450
|
+
// return true if event data is found and digest is different
|
|
451
|
+
return existingEvent && event.digest !== existingEvent.digest;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
438
454
|
/**
|
|
439
455
|
* Calculates events that were deleted (present in old listings but not in new)
|
|
440
456
|
*/
|
|
@@ -466,16 +482,20 @@ class ProjectImpl extends Emitter {
|
|
|
466
482
|
/**
|
|
467
483
|
* Emits events based on created and deleted events
|
|
468
484
|
*/
|
|
469
|
-
_emitListingsEvents(createdEvents, deletedEvents) {
|
|
485
|
+
_emitListingsEvents(createdEvents, updatedEvents, deletedEvents) {
|
|
470
486
|
const hasCreatedEvents = createdEvents.length > 0;
|
|
471
487
|
const hasDeletedEvents = deletedEvents.length > 0;
|
|
472
|
-
const
|
|
488
|
+
const hasUpdatedEvents = updatedEvents.length > 0;
|
|
489
|
+
const hasChanges = hasCreatedEvents || hasDeletedEvents || hasUpdatedEvents;
|
|
473
490
|
if (hasCreatedEvents) {
|
|
474
491
|
this.emit('listings_events_created', createdEvents);
|
|
475
492
|
}
|
|
476
493
|
if (hasDeletedEvents) {
|
|
477
494
|
this.emit('listings_events_deleted', deletedEvents);
|
|
478
495
|
}
|
|
496
|
+
if (hasUpdatedEvents) {
|
|
497
|
+
this.emit('listings_events_updated', updatedEvents);
|
|
498
|
+
}
|
|
479
499
|
if (hasChanges) {
|
|
480
500
|
this.emit('listings');
|
|
481
501
|
}
|
|
@@ -669,9 +689,13 @@ function onProjectFieldsUpdated(project, callback) {
|
|
|
669
689
|
return subscribe$2(project, 'updated', callback);
|
|
670
690
|
}
|
|
671
691
|
/**
|
|
672
|
-
*
|
|
692
|
+
* Adds an observer that is called when the project listings are updated.
|
|
693
|
+
*
|
|
694
|
+
* @deprecated Use {@link onEventAdded()}, {@link onEventUpdated()} and
|
|
695
|
+
* {@link onEventRemoved()} instead
|
|
673
696
|
*/
|
|
674
697
|
function onProjectListingsUpdated(project, callback) {
|
|
698
|
+
console.warn('onProjectListingsUpdated() is deprecated. Please use onEventAdded(), onEventUpdated() and onEventRemoved() instead');
|
|
675
699
|
return subscribe$2(project, 'listings', callback);
|
|
676
700
|
}
|
|
677
701
|
|
|
@@ -794,11 +818,12 @@ class EventImpl extends Emitter {
|
|
|
794
818
|
this._context = context;
|
|
795
819
|
this._state = this.calculateState();
|
|
796
820
|
this._internalState = this.calculateInternalState();
|
|
797
|
-
this.
|
|
798
|
-
this.
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
this.
|
|
821
|
+
this.boundHandleState = this.handleState.bind(this);
|
|
822
|
+
this.boundHandleInternalState = this.handleInternalState.bind(this);
|
|
823
|
+
this.boundHandleEventsUpdated = this.handleEventsUpdated.bind(this);
|
|
824
|
+
this.unsubscribeStateHandler = onTick(this.boundHandleState);
|
|
825
|
+
this.unsubscribeInternalStateHandler = onTick(this.boundHandleInternalState);
|
|
826
|
+
this.unsubscribeListingsHandler = subscribe$2(this.context.project, 'listings_events_updated', this.boundHandleEventsUpdated);
|
|
802
827
|
}
|
|
803
828
|
calculateState() {
|
|
804
829
|
if (!this._data.started || now() < this.startAt) {
|
|
@@ -841,11 +866,13 @@ class EventImpl extends Emitter {
|
|
|
841
866
|
this.emit('internal_state', internalState);
|
|
842
867
|
}
|
|
843
868
|
}
|
|
844
|
-
|
|
845
|
-
const {
|
|
846
|
-
const data = project.events.find(({ id }) => id === this.id);
|
|
869
|
+
handleEventsUpdated(events) {
|
|
870
|
+
const data = events.find(({ id }) => id === this.id);
|
|
847
871
|
if (data && this._data.digest !== data.digest) {
|
|
848
872
|
this._data = data;
|
|
873
|
+
// Forcing state recalculation to ensure the event is in the correct state
|
|
874
|
+
this.handleState();
|
|
875
|
+
this.handleInternalState();
|
|
849
876
|
this.emit('updated');
|
|
850
877
|
}
|
|
851
878
|
}
|