Skip to content

Commit 7e8e861

Browse files
authored
Merge pull request nasa#1372 from nasa/api-review-followup-1122
[API] Address review followup items
2 parents df2ce72 + 2cde802 commit 7e8e861

File tree

4 files changed

+65
-26
lines changed

4 files changed

+65
-26
lines changed

API.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ provider.
129129

130130
The "composition" of a domain object is the list of objects it contains,
131131
as shown (for example) in the tree for browsing. Open MCT provides a
132-
default solution for composition, but there may be cases where you want
133-
to provide the composition of a certain object (or type of object) dynamically.
132+
[default solution](#default-composition-provider) for composition, but there
133+
may be cases where you want to provide the composition of a certain object
134+
(or type of object) dynamically.
135+
134136
For instance, you may want to populate a hierarchy under a custom root-level
135137
object based on the contents of a telemetry dictionary.
136138
To do this, you can add a new CompositionProvider:
@@ -146,6 +148,29 @@ openmct.composition.addProvider({
146148
});
147149
```
148150

151+
#### Default Composition Provider
152+
153+
The default composition provider applies to any domain object with
154+
a `composition` property. The value of `composition` should be an
155+
array of identifiers, e.g.:
156+
157+
```js
158+
var domainObject = {
159+
name: "My Object",
160+
type: 'folder',
161+
composition: [
162+
{
163+
key: '412229c3-922c-444b-8624-736d85516247',
164+
namespace: 'foo'
165+
},
166+
{
167+
key: 'd6e0ce02-5b85-4e55-8006-a8a505b64c75',
168+
namespace: 'foo'
169+
}
170+
]
171+
};
172+
```
173+
149174
### Adding Telemetry Providers
150175

151176
When connecting to a new telemetry source, you will want to register a new

src/api/objects/LegacyObjectAPIInterceptor.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
*****************************************************************************/
2222

2323
define([
24-
'./object-utils',
25-
'./objectEventEmitter'
24+
'./object-utils'
2625
], function (
27-
utils,
28-
objectEventEmitter
26+
utils
2927
) {
30-
function ObjectServiceProvider(objectService, instantiate, topic) {
28+
function ObjectServiceProvider(eventEmitter, objectService, instantiate, topic) {
29+
this.eventEmitter = eventEmitter;
3130
this.objectService = objectService;
3231
this.instantiate = instantiate;
3332

@@ -61,12 +60,12 @@ define([
6160
var newStyleObject = utils.toNewFormat(legacyObject.getModel(), legacyObject.getId());
6261

6362
//Don't trigger self
64-
objectEventEmitter.off('mutation', handleMutation);
65-
objectEventEmitter.emit(newStyleObject.identifier.key + ":*", newStyleObject);
66-
objectEventEmitter.on('mutation', handleMutation);
63+
this.eventEmitter.off('mutation', handleMutation);
64+
this.eventEmitter.emit(newStyleObject.identifier.key + ":*", newStyleObject);
65+
this.eventEmitter.on('mutation', handleMutation);
6766
}.bind(this);
6867

69-
objectEventEmitter.on('mutation', handleMutation);
68+
this.eventEmitter.on('mutation', handleMutation);
7069
removeGeneralTopicListener = this.generalTopic.listen(handleLegacyMutation);
7170
};
7271

@@ -96,6 +95,8 @@ define([
9695
// Injects new object API as a decorator so that it hijacks all requests.
9796
// Object providers implemented on new API should just work, old API should just work, many things may break.
9897
function LegacyObjectAPIInterceptor(openmct, ROOTS, instantiate, topic, objectService) {
98+
var eventEmitter = openmct.objects.eventEmitter;
99+
99100
this.getObjects = function (keys) {
100101
var results = {},
101102
promises = keys.map(function (keyString) {
@@ -114,7 +115,12 @@ define([
114115
};
115116

116117
openmct.objects.supersecretSetFallbackProvider(
117-
new ObjectServiceProvider(objectService, instantiate, topic)
118+
new ObjectServiceProvider(
119+
eventEmitter,
120+
objectService,
121+
instantiate,
122+
topic
123+
)
118124
);
119125

120126
ROOTS.forEach(function (r) {

src/api/objects/MutableObject.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
*****************************************************************************/
2222

2323
define([
24-
'lodash',
25-
'./objectEventEmitter'
24+
'lodash'
2625
], function (
27-
_,
28-
objectEventEmitter
26+
_
2927
) {
3028
var ANY_OBJECT_EVENT = "mutation";
3129

@@ -36,7 +34,8 @@ define([
3634
* @param object
3735
* @interface MutableObject
3836
*/
39-
function MutableObject(object) {
37+
function MutableObject(eventEmitter, object) {
38+
this.eventEmitter = eventEmitter;
4039
this.object = object;
4140
this.unlisteners = [];
4241
}
@@ -61,8 +60,11 @@ define([
6160
*/
6261
MutableObject.prototype.on = function (path, callback) {
6362
var fullPath = qualifiedEventName(this.object, path);
64-
objectEventEmitter.on(fullPath, callback);
65-
this.unlisteners.push(objectEventEmitter.off.bind(objectEventEmitter, fullPath, callback));
63+
var eventOff =
64+
this.eventEmitter.off.bind(this.eventEmitter, fullPath, callback);
65+
66+
this.eventEmitter.on(fullPath, callback);
67+
this.unlisteners.push(eventOff);
6668
};
6769

6870
/**
@@ -78,12 +80,12 @@ define([
7880
_.set(this.object, 'modified', Date.now());
7981

8082
//Emit event specific to property
81-
objectEventEmitter.emit(qualifiedEventName(this.object, path), value);
83+
this.eventEmitter.emit(qualifiedEventName(this.object, path), value);
8284
//Emit wildcare event
83-
objectEventEmitter.emit(qualifiedEventName(this.object, '*'), this.object);
85+
this.eventEmitter.emit(qualifiedEventName(this.object, '*'), this.object);
8486

8587
//Emit a general "any object" event
86-
objectEventEmitter.emit(ANY_OBJECT_EVENT, this.object);
88+
this.eventEmitter.emit(ANY_OBJECT_EVENT, this.object);
8789
};
8890

8991
return MutableObject;

src/api/objects/ObjectAPI.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ define([
2525
'./object-utils',
2626
'./MutableObject',
2727
'./RootRegistry',
28-
'./RootObjectProvider'
28+
'./RootObjectProvider',
29+
'EventEmitter'
2930
], function (
3031
_,
3132
utils,
3233
MutableObject,
3334
RootRegistry,
34-
RootObjectProvider
35+
RootObjectProvider,
36+
EventEmitter
3537
) {
3638

3739

@@ -42,6 +44,7 @@ define([
4244
*/
4345

4446
function ObjectAPI() {
47+
this.eventEmitter = new EventEmitter();
4548
this.providers = {};
4649
this.rootRegistry = new RootRegistry();
4750
this.rootProvider = new RootObjectProvider(this.rootRegistry);
@@ -175,7 +178,9 @@ define([
175178
* @memberof module:openmct.ObjectAPI#
176179
*/
177180
ObjectAPI.prototype.mutate = function (domainObject, path, value) {
178-
return new MutableObject(domainObject).set(path, value);
181+
var mutableObject =
182+
new MutableObject(this.eventEmitter, domainObject);
183+
return mutableObject.set(path, value);
179184
};
180185

181186
/**
@@ -188,7 +193,8 @@ define([
188193
* @memberof module:openmct.ObjectAPI#
189194
*/
190195
ObjectAPI.prototype.observe = function (domainObject, path, callback) {
191-
var mutableObject = new MutableObject(domainObject);
196+
var mutableObject =
197+
new MutableObject(this.eventEmitter, domainObject);
192198
mutableObject.on(path, callback);
193199
return mutableObject.stopListening.bind(mutableObject);
194200
};

0 commit comments

Comments
 (0)