Skip to content

Commit d7edfb4

Browse files
authored
Merge pull request #1263 from nasa/revert-1252-async-root-registration
Revert "Async root registration"
2 parents 56a6628 + 4eca80a commit d7edfb4

File tree

10 files changed

+52
-324
lines changed

10 files changed

+52
-324
lines changed

Diff for: API.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,18 @@ To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method
118118
of the [object API]{@link module:openmct.ObjectAPI}:
119119

120120
```
121-
openmct.objects.addRoot({ key: "my-key", namespace: "my-namespace" });
121+
openmct.objects.addRoot({
122+
identifier: { key: "my-key", namespace: "my-namespace" }
123+
name: "My Root-level Object",
124+
type: "my-type"
125+
});
122126
```
123127

124-
Root objects are loaded just like any other objects, i.e. via an object
125-
provider.
128+
You can also remove this root-level object via its identifier:
129+
130+
```
131+
openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" });
132+
```
126133

127134
### Adding Composition Providers
128135

Diff for: index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
[
3333
'example/imagery',
3434
'example/eventGenerator',
35-
'example/generator',
36-
'platform/features/my-items'
35+
'example/generator'
3736
].forEach(
3837
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
3938
);

Diff for: platform/core/bundle.js

+10
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,16 @@ define([
409409
]
410410
}
411411
],
412+
"roots": [
413+
{
414+
"id": "mine",
415+
"model": {
416+
"name": "My Items",
417+
"type": "folder",
418+
"composition": []
419+
}
420+
}
421+
],
412422
"runs": [
413423
{
414424
"implementation": TransactingMutationListener,

Diff for: platform/features/my-items/bundle.js

-45
This file was deleted.

Diff for: src/api/objects/ObjectAPI.js

+31-12
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
define([
2424
'lodash',
2525
'./object-utils',
26-
'./MutableObject',
27-
'./RootRegistry',
28-
'./RootObjectProvider'
26+
'./MutableObject'
2927
], function (
3028
_,
3129
utils,
32-
MutableObject,
33-
RootRegistry,
34-
RootObjectProvider
30+
MutableObject
3531
) {
3632

3733

@@ -44,8 +40,16 @@ define([
4440

4541
function ObjectAPI() {
4642
this.providers = {};
47-
this.rootRegistry = new RootRegistry();
48-
this.rootProvider = new RootObjectProvider(this.rootRegistry);
43+
this.rootRegistry = [];
44+
this.rootProvider = {
45+
'get': function () {
46+
return Promise.resolve({
47+
name: 'The root object',
48+
type: 'root',
49+
composition: this.rootRegistry
50+
});
51+
}.bind(this)
52+
};
4953
}
5054

5155
ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) {
@@ -139,14 +143,29 @@ define([
139143

140144
/**
141145
* Add a root-level object.
142-
* @param {module:openmct.ObjectAPI~Identifier|function} an array of
143-
* identifiers for root level objects, or a function that returns a
144-
* promise for an identifier or an array of root level objects.
146+
* @param {module:openmct.DomainObject} domainObject the root-level object
147+
* to add.
145148
* @method addRoot
146149
* @memberof module:openmct.ObjectAPI#
147150
*/
148151
ObjectAPI.prototype.addRoot = function (key) {
149-
this.rootRegistry.addRoot(key);
152+
this.rootRegistry.unshift(key);
153+
};
154+
155+
/**
156+
* Remove a root-level object.
157+
* @param {module:openmct.ObjectAPI~Identifier} id the identifier of the
158+
* root-level object to remove.
159+
* @method removeRoot
160+
* @memberof module:openmct.ObjectAPI#
161+
*/
162+
ObjectAPI.prototype.removeRoot = function (key) {
163+
this.rootRegistry = this.rootRegistry.filter(function (k) {
164+
return (
165+
k.identifier !== key.identifier ||
166+
k.namespace !== key.namespace
167+
);
168+
});
150169
};
151170

152171
/**

Diff for: src/api/objects/RootObjectProvider.js

-43
This file was deleted.

Diff for: src/api/objects/RootRegistry.js

-57
This file was deleted.

Diff for: src/api/objects/test/RootObjectProviderSpec.js

-59
This file was deleted.

0 commit comments

Comments
 (0)