diff --git a/src/adapter/services/LegacyObjectAPIInterceptor.js b/src/adapter/services/LegacyObjectAPIInterceptor.js index ac011e12e1..9f6aafcdc8 100644 --- a/src/adapter/services/LegacyObjectAPIInterceptor.js +++ b/src/adapter/services/LegacyObjectAPIInterceptor.js @@ -58,11 +58,8 @@ define([ handleLegacyMutation = function (legacyObject) { var newStyleObject = utils.toNewFormat(legacyObject.getModel(), legacyObject.getId()); - - //Don't trigger self - this.eventEmitter.off('mutation', handleMutation); this.eventEmitter.emit(newStyleObject.identifier.key + ":*", newStyleObject); - this.eventEmitter.on('mutation', handleMutation); + this.eventEmitter.emit('mutation', newStyleObject); }.bind(this); this.eventEmitter.on('mutation', handleMutation); diff --git a/src/api/composition/DefaultCompositionProvider.js b/src/api/composition/DefaultCompositionProvider.js index 3399a7306d..fdb8dbb913 100644 --- a/src/api/composition/DefaultCompositionProvider.js +++ b/src/api/composition/DefaultCompositionProvider.js @@ -46,6 +46,7 @@ define([ function DefaultCompositionProvider(publicAPI, compositionAPI) { this.publicAPI = publicAPI; this.listeningTo = {}; + this.onMutation = this.onMutation.bind(this); this.cannotContainDuplicates = this.cannotContainDuplicates.bind(this); this.cannotContainItself = this.cannotContainItself.bind(this); @@ -208,9 +209,10 @@ define([ if (this.topicListener) { return; } - var topic = this.publicAPI.$injector.get('topic'); - var mutation = topic('mutation'); - this.topicListener = mutation.listen(this.onMutation.bind(this)); + this.publicAPI.objects.eventEmitter.on('mutation', this.onMutation); + this.topicListener = () => { + this.publicAPI.objects.eventEmitter.off('mutation', this.onMutation) + }; }; /** @@ -220,7 +222,7 @@ define([ * @private */ DefaultCompositionProvider.prototype.onMutation = function (oldDomainObject) { - var id = oldDomainObject.getId(); + var id = objectUtils.makeKeyString(oldDomainObject.identifier); var listeners = this.listeningTo[id]; if (!listeners) { @@ -228,7 +230,7 @@ define([ } var oldComposition = listeners.composition.map(objectUtils.makeKeyString); - var newComposition = oldDomainObject.getModel().composition.map(objectUtils.makeKeyString); + var newComposition = oldDomainObject.composition.map(objectUtils.makeKeyString); var added = _.difference(newComposition, oldComposition).map(objectUtils.parseKeyString); var removed = _.difference(oldComposition, newComposition).map(objectUtils.parseKeyString); diff --git a/src/api/objects/MutableObject.js b/src/api/objects/MutableObject.js index dd718d7975..110c256dbe 100644 --- a/src/api/objects/MutableObject.js +++ b/src/api/objects/MutableObject.js @@ -83,18 +83,15 @@ define([ this.object = newObject; }.bind(this); - this.eventEmitter.on(qualifiedEventName(this.object, '*'), handleRecursiveMutation); - - //Emit event specific to property - this.eventEmitter.emit(qualifiedEventName(this.object, path), value); - - this.eventEmitter.off(qualifiedEventName(this.object, '*'), handleRecursiveMutation); - - //Emit wildcare event + //Emit wildcard event this.eventEmitter.emit(qualifiedEventName(this.object, '*'), this.object); - //Emit a general "any object" event this.eventEmitter.emit(ANY_OBJECT_EVENT, this.object); + + this.eventEmitter.on(qualifiedEventName(this.object, '*'), handleRecursiveMutation); + //Emit event specific to property + this.eventEmitter.emit(qualifiedEventName(this.object, path), value); + this.eventEmitter.off(qualifiedEventName(this.object, '*'), handleRecursiveMutation); }; return MutableObject; diff --git a/src/plugins/telemetryTable/TelemetryTable.js b/src/plugins/telemetryTable/TelemetryTable.js index 43d48c0d38..8672674e13 100644 --- a/src/plugins/telemetryTable/TelemetryTable.js +++ b/src/plugins/telemetryTable/TelemetryTable.js @@ -79,8 +79,8 @@ define([ loadComposition() { this.tableComposition = this.openmct.composition.get(this.domainObject); - if (this.tableComposition !== undefined){ - this.tableComposition.load().then((composition)=>{ + if (this.tableComposition !== undefined) { + this.tableComposition.load().then((composition) => { composition = composition.filter(this.isTelemetryObject); this.configuration.addColumnsForAllObjects(composition); @@ -122,7 +122,6 @@ define([ let telemetryRows = telemetryData.map(datum => new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator)); this.boundedRows.add(telemetryRows); - console.log('Loaded %i rows', telemetryRows.length); this.decrementOutstandingRequests(); }); } @@ -131,7 +130,7 @@ define([ * @private */ incrementOutstandingRequests() { - if (this.outstandingRequests === 0){ + if (this.outstandingRequests === 0) { this.emit('outstanding-requests', true); } this.outstandingRequests++; @@ -143,7 +142,7 @@ define([ decrementOutstandingRequests() { this.outstandingRequests--; - if (this.outstandingRequests === 0){ + if (this.outstandingRequests === 0) { this.emit('outstanding-requests', false); } } diff --git a/src/plugins/telemetryTable/TelemetryTableConfiguration.js b/src/plugins/telemetryTable/TelemetryTableConfiguration.js index f4df3dfc12..6dadb31558 100644 --- a/src/plugins/telemetryTable/TelemetryTableConfiguration.js +++ b/src/plugins/telemetryTable/TelemetryTableConfiguration.js @@ -64,6 +64,7 @@ define([ objectMutated(object) { //Synchronize domain object reference. Duplicate object otherwise change detection becomes impossible. this.domainObject = object; + //Was it the configuration that changed? if (!_.eq(object.configuration, this.oldConfiguration)) { //Make copy of configuration, otherwise change detection is impossible if shared instance is being modified. this.oldConfiguration = JSON.parse(JSON.stringify(this.getConfiguration())); @@ -91,16 +92,19 @@ define([ let columnsToRemove = this.columns[objectKeyString]; delete this.columns[objectKeyString]; + + let configuration = this.domainObject.configuration; + let configurationChanged = false; columnsToRemove.forEach((column) => { //There may be more than one column with the same key (eg. time system columns) if (!this.hasColumnWithKey(column.getKey())) { - let configuration = this.domainObject.configuration; delete configuration.hiddenColumns[column.getKey()]; - // If there are no more columns with this key, delete any configuration, and trigger - // a column refresh. - this.openmct.objects.mutate(this.domainObject, 'configuration', configuration); + configurationChanged = true; } }); + if (configurationChanged) { + this.updateConfiguration(configuration); + } } hasColumnWithKey(columnKey) {