mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
Adding compatibility between old and new style mutation events
This commit is contained in:
parent
9c88b7ce1d
commit
8c439d8109
@ -1,15 +1,44 @@
|
||||
define([
|
||||
'./object-utils',
|
||||
'./ObjectAPI'
|
||||
'./ObjectAPI',
|
||||
'./objectEventBus'
|
||||
], function (
|
||||
utils,
|
||||
ObjectAPI
|
||||
ObjectAPI,
|
||||
objectEventBus
|
||||
) {
|
||||
function ObjectServiceProvider(objectService, instantiate) {
|
||||
function ObjectServiceProvider(objectService, instantiate, topic) {
|
||||
this.objectService = objectService;
|
||||
this.instantiate = instantiate;
|
||||
|
||||
this.topicService = topic;
|
||||
this.generalTopic = topic('mutation');
|
||||
this.bridgeEventBuses(this.topicService, this.generalTopic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bridges old and new style mutation events to provide compatibility between the two APIs
|
||||
* @private
|
||||
*/
|
||||
ObjectServiceProvider.prototype.bridgeEventBuses = function (topicService, generalTopic) {
|
||||
|
||||
function handleMutation(newStyleObject) {
|
||||
var oldStyleObject = utils.toOldFormat(newStyleObject);
|
||||
var specificTopic = topicService("mutation:" + oldStyleObject.getId());
|
||||
|
||||
generalTopic.notify(oldStyleObject);
|
||||
specificTopic.notify(oldStyleObject.getModel());
|
||||
}
|
||||
|
||||
function handleLegacyMutation(legacyObject){
|
||||
var newStyleObject = utils.toNewFormat(legacyObject.getModel(), legacyObject.getId());
|
||||
objectEventBus.emit(newStyleObject.key.identifier + ":*", newStyleObject);
|
||||
}
|
||||
|
||||
objectEventBus.on('mutation', handleMutation)
|
||||
generalTopic.listen(handleLegacyMutation);
|
||||
};
|
||||
|
||||
ObjectServiceProvider.prototype.save = function (object) {
|
||||
var key = object.key,
|
||||
keyString = utils.makeKeyString(key),
|
||||
|
@ -83,7 +83,17 @@ define([
|
||||
};
|
||||
|
||||
Objects.getMutable = function (object) {
|
||||
return new MutableObject(eventEmitter, object);
|
||||
var mutable = new MutableObject(eventEmitter, object);
|
||||
var id = object.key.identifier;
|
||||
var specificTopic = topic("mutation:" + id);
|
||||
|
||||
function legacyEvent (modifiedObject) {
|
||||
specificTopic.notify(utils.toOldFormat(modifiedObject));
|
||||
};
|
||||
|
||||
// Add legacy event support
|
||||
mutable.on("*", legacyEvent);
|
||||
return mutable;
|
||||
};
|
||||
|
||||
return Objects;
|
||||
|
10
src/api/objects/objectEventBus.js
Normal file
10
src/api/objects/objectEventBus.js
Normal file
@ -0,0 +1,10 @@
|
||||
define([
|
||||
"EventEmitter"
|
||||
], function (
|
||||
EventEmitter
|
||||
) {
|
||||
/**
|
||||
* Provides a singleton event bus for sharing between objects.
|
||||
*/
|
||||
return new EventEmitter();
|
||||
});
|
Loading…
Reference in New Issue
Block a user