mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
Merge pull request #1263 from nasa/revert-1252-async-root-registration
Revert "Async root registration"
This commit is contained in:
commit
d7edfb4cc6
13
API.md
13
API.md
@ -118,11 +118,18 @@ To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method
|
|||||||
of the [object API]{@link module:openmct.ObjectAPI}:
|
of the [object API]{@link module:openmct.ObjectAPI}:
|
||||||
|
|
||||||
```
|
```
|
||||||
openmct.objects.addRoot({ key: "my-key", namespace: "my-namespace" });
|
openmct.objects.addRoot({
|
||||||
|
identifier: { key: "my-key", namespace: "my-namespace" }
|
||||||
|
name: "My Root-level Object",
|
||||||
|
type: "my-type"
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Root objects are loaded just like any other objects, i.e. via an object
|
You can also remove this root-level object via its identifier:
|
||||||
provider.
|
|
||||||
|
```
|
||||||
|
openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" });
|
||||||
|
```
|
||||||
|
|
||||||
### Adding Composition Providers
|
### Adding Composition Providers
|
||||||
|
|
||||||
|
@ -32,8 +32,7 @@
|
|||||||
[
|
[
|
||||||
'example/imagery',
|
'example/imagery',
|
||||||
'example/eventGenerator',
|
'example/eventGenerator',
|
||||||
'example/generator',
|
'example/generator'
|
||||||
'platform/features/my-items'
|
|
||||||
].forEach(
|
].forEach(
|
||||||
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
|
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
|
||||||
);
|
);
|
||||||
|
@ -409,6 +409,16 @@ define([
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"roots": [
|
||||||
|
{
|
||||||
|
"id": "mine",
|
||||||
|
"model": {
|
||||||
|
"name": "My Items",
|
||||||
|
"type": "folder",
|
||||||
|
"composition": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"runs": [
|
"runs": [
|
||||||
{
|
{
|
||||||
"implementation": TransactingMutationListener,
|
"implementation": TransactingMutationListener,
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
* Open MCT includes source code licensed under additional open source
|
|
||||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
* this source code distribution or the Licensing information page available
|
|
||||||
* at runtime from the About dialog for additional information.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
define([
|
|
||||||
'legacyRegistry'
|
|
||||||
], function (
|
|
||||||
legacyRegistry
|
|
||||||
) {
|
|
||||||
|
|
||||||
legacyRegistry.register("platform/features/my-items", {
|
|
||||||
"name": "My Items",
|
|
||||||
"description": "Defines a root named My Items",
|
|
||||||
"extensions": {
|
|
||||||
"roots": [
|
|
||||||
{
|
|
||||||
"id": "mine",
|
|
||||||
"model": {
|
|
||||||
"name": "My Items",
|
|
||||||
"type": "folder",
|
|
||||||
"composition": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
@ -23,15 +23,11 @@
|
|||||||
define([
|
define([
|
||||||
'lodash',
|
'lodash',
|
||||||
'./object-utils',
|
'./object-utils',
|
||||||
'./MutableObject',
|
'./MutableObject'
|
||||||
'./RootRegistry',
|
|
||||||
'./RootObjectProvider'
|
|
||||||
], function (
|
], function (
|
||||||
_,
|
_,
|
||||||
utils,
|
utils,
|
||||||
MutableObject,
|
MutableObject
|
||||||
RootRegistry,
|
|
||||||
RootObjectProvider
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|
||||||
@ -44,8 +40,16 @@ define([
|
|||||||
|
|
||||||
function ObjectAPI() {
|
function ObjectAPI() {
|
||||||
this.providers = {};
|
this.providers = {};
|
||||||
this.rootRegistry = new RootRegistry();
|
this.rootRegistry = [];
|
||||||
this.rootProvider = new RootObjectProvider(this.rootRegistry);
|
this.rootProvider = {
|
||||||
|
'get': function () {
|
||||||
|
return Promise.resolve({
|
||||||
|
name: 'The root object',
|
||||||
|
type: 'root',
|
||||||
|
composition: this.rootRegistry
|
||||||
|
});
|
||||||
|
}.bind(this)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) {
|
ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) {
|
||||||
@ -139,14 +143,29 @@ define([
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a root-level object.
|
* Add a root-level object.
|
||||||
* @param {module:openmct.ObjectAPI~Identifier|function} an array of
|
* @param {module:openmct.DomainObject} domainObject the root-level object
|
||||||
* identifiers for root level objects, or a function that returns a
|
* to add.
|
||||||
* promise for an identifier or an array of root level objects.
|
|
||||||
* @method addRoot
|
* @method addRoot
|
||||||
* @memberof module:openmct.ObjectAPI#
|
* @memberof module:openmct.ObjectAPI#
|
||||||
*/
|
*/
|
||||||
ObjectAPI.prototype.addRoot = function (key) {
|
ObjectAPI.prototype.addRoot = function (key) {
|
||||||
this.rootRegistry.addRoot(key);
|
this.rootRegistry.unshift(key);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a root-level object.
|
||||||
|
* @param {module:openmct.ObjectAPI~Identifier} id the identifier of the
|
||||||
|
* root-level object to remove.
|
||||||
|
* @method removeRoot
|
||||||
|
* @memberof module:openmct.ObjectAPI#
|
||||||
|
*/
|
||||||
|
ObjectAPI.prototype.removeRoot = function (key) {
|
||||||
|
this.rootRegistry = this.rootRegistry.filter(function (k) {
|
||||||
|
return (
|
||||||
|
k.identifier !== key.identifier ||
|
||||||
|
k.namespace !== key.namespace
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
* Open MCT includes source code licensed under additional open source
|
|
||||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
* this source code distribution or the Licensing information page available
|
|
||||||
* at runtime from the About dialog for additional information.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
define([
|
|
||||||
], function (
|
|
||||||
) {
|
|
||||||
|
|
||||||
function RootObjectProvider(rootRegistry) {
|
|
||||||
this.rootRegistry = rootRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
RootObjectProvider.prototype.get = function () {
|
|
||||||
return this.rootRegistry.getRoots()
|
|
||||||
.then(function (roots) {
|
|
||||||
return {
|
|
||||||
name: 'The root object',
|
|
||||||
type: 'root',
|
|
||||||
composition: roots
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return RootObjectProvider;
|
|
||||||
});
|
|
@ -1,57 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
* Open MCT includes source code licensed under additional open source
|
|
||||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
* this source code distribution or the Licensing information page available
|
|
||||||
* at runtime from the About dialog for additional information.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
define([
|
|
||||||
'lodash'
|
|
||||||
], function (
|
|
||||||
_
|
|
||||||
) {
|
|
||||||
|
|
||||||
function RootRegistry() {
|
|
||||||
this.providers = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
RootRegistry.prototype.getRoots = function () {
|
|
||||||
var promises = this.providers.map(function (provider) {
|
|
||||||
return provider();
|
|
||||||
});
|
|
||||||
return Promise.all(promises)
|
|
||||||
.then(_.flatten);
|
|
||||||
};
|
|
||||||
|
|
||||||
function isKey(key) {
|
|
||||||
return _.isObject(key) && _.has(key, 'key') && _.has(key, 'namespace');
|
|
||||||
}
|
|
||||||
|
|
||||||
RootRegistry.prototype.addRoot = function (key) {
|
|
||||||
if (isKey(key) || (_.isArray(key) && _.every(key, isKey))) {
|
|
||||||
this.providers.push(function () {
|
|
||||||
return key;
|
|
||||||
});
|
|
||||||
} else if (_.isFunction(key)) {
|
|
||||||
this.providers.push(key);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return RootRegistry;
|
|
||||||
|
|
||||||
});
|
|
@ -1,59 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
* Open MCT includes source code licensed under additional open source
|
|
||||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
* this source code distribution or the Licensing information page available
|
|
||||||
* at runtime from the About dialog for additional information.
|
|
||||||
*****************************************************************************/
|
|
||||||
define([
|
|
||||||
'../RootObjectProvider'
|
|
||||||
], function (
|
|
||||||
RootObjectProvider
|
|
||||||
) {
|
|
||||||
describe('RootObjectProvider', function () {
|
|
||||||
var rootRegistry,
|
|
||||||
rootObjectProvider;
|
|
||||||
|
|
||||||
function done() {
|
|
||||||
var isDone = false;
|
|
||||||
waitsFor(function () {
|
|
||||||
return isDone;
|
|
||||||
});
|
|
||||||
return function () {
|
|
||||||
isDone = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
rootRegistry = jasmine.createSpyObj('rootRegistry', ['getRoots']);
|
|
||||||
rootRegistry.getRoots.andReturn(Promise.resolve(['some root']));
|
|
||||||
rootObjectProvider = new RootObjectProvider(rootRegistry);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('supports fetching root', function () {
|
|
||||||
rootObjectProvider.get()
|
|
||||||
.then(function (root) {
|
|
||||||
expect(root).toEqual({
|
|
||||||
name: 'The root object',
|
|
||||||
type: 'root',
|
|
||||||
composition: ['some root']
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(done());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,102 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
* Open MCT includes source code licensed under additional open source
|
|
||||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
* this source code distribution or the Licensing information page available
|
|
||||||
* at runtime from the About dialog for additional information.
|
|
||||||
*****************************************************************************/
|
|
||||||
define([
|
|
||||||
'../RootRegistry'
|
|
||||||
], function (
|
|
||||||
RootRegistry
|
|
||||||
) {
|
|
||||||
describe('RootRegistry', function () {
|
|
||||||
var idA,
|
|
||||||
idB,
|
|
||||||
idC,
|
|
||||||
registry;
|
|
||||||
|
|
||||||
function done() {
|
|
||||||
var isDone = false;
|
|
||||||
waitsFor(function () {
|
|
||||||
return isDone;
|
|
||||||
});
|
|
||||||
return function () {
|
|
||||||
isDone = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
idA = {key: 'keyA', namespace: 'something'};
|
|
||||||
idB = {key: 'keyB', namespace: 'something'};
|
|
||||||
idC = {key: 'keyC', namespace: 'something'};
|
|
||||||
registry = new RootRegistry();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can register a root by key', function () {
|
|
||||||
registry.addRoot(idA);
|
|
||||||
registry.getRoots()
|
|
||||||
.then(function (roots) {
|
|
||||||
expect(roots).toEqual([idA]);
|
|
||||||
})
|
|
||||||
.then(done());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can register multiple roots by key', function () {
|
|
||||||
registry.addRoot([idA, idB]);
|
|
||||||
registry.getRoots()
|
|
||||||
.then(function (roots) {
|
|
||||||
expect(roots).toEqual([idA, idB]);
|
|
||||||
})
|
|
||||||
.then(done());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can register an asynchronous root ', function () {
|
|
||||||
registry.addRoot(function () {
|
|
||||||
return Promise.resolve(idA);
|
|
||||||
});
|
|
||||||
registry.getRoots()
|
|
||||||
.then(function (roots) {
|
|
||||||
expect(roots).toEqual([idA]);
|
|
||||||
})
|
|
||||||
.then(done());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can register multiple asynchronous roots', function () {
|
|
||||||
registry.addRoot(function () {
|
|
||||||
return Promise.resolve([idA, idB]);
|
|
||||||
});
|
|
||||||
registry.getRoots()
|
|
||||||
.then(function (roots) {
|
|
||||||
expect(roots).toEqual([idA, idB]);
|
|
||||||
})
|
|
||||||
.then(done());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can combine different types of registration', function () {
|
|
||||||
registry.addRoot([idA, idB]);
|
|
||||||
registry.addRoot(function () {
|
|
||||||
return Promise.resolve([idC]);
|
|
||||||
});
|
|
||||||
registry.getRoots()
|
|
||||||
.then(function (roots) {
|
|
||||||
expect(roots).toEqual([idA, idB, idC]);
|
|
||||||
})
|
|
||||||
.then(done());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -72,7 +72,6 @@ define([
|
|||||||
'../platform/features/conductor-v2/utcTimeSystem/bundle',
|
'../platform/features/conductor-v2/utcTimeSystem/bundle',
|
||||||
'../platform/features/imagery/bundle',
|
'../platform/features/imagery/bundle',
|
||||||
'../platform/features/layout/bundle',
|
'../platform/features/layout/bundle',
|
||||||
'../platform/features/my-items/bundle',
|
|
||||||
'../platform/features/pages/bundle',
|
'../platform/features/pages/bundle',
|
||||||
'../platform/features/plot/bundle',
|
'../platform/features/plot/bundle',
|
||||||
'../platform/features/static-markup/bundle',
|
'../platform/features/static-markup/bundle',
|
||||||
|
Loading…
Reference in New Issue
Block a user