Merge pull request #1263 from nasa/revert-1252-async-root-registration

Revert "Async root registration"
This commit is contained in:
Victor Woeltjen 2016-10-18 10:52:42 -07:00 committed by GitHub
commit d7edfb4cc6
10 changed files with 52 additions and 324 deletions

13
API.md
View File

@ -118,11 +118,18 @@ To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method
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
provider.
You can also remove this root-level object via its identifier:
```
openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" });
```
### Adding Composition Providers

View File

@ -32,8 +32,7 @@
[
'example/imagery',
'example/eventGenerator',
'example/generator',
'platform/features/my-items'
'example/generator'
].forEach(
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
);

View File

@ -409,6 +409,16 @@ define([
]
}
],
"roots": [
{
"id": "mine",
"model": {
"name": "My Items",
"type": "folder",
"composition": []
}
}
],
"runs": [
{
"implementation": TransactingMutationListener,

View File

@ -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": []
}
}
]
}
});
});

View File

@ -23,15 +23,11 @@
define([
'lodash',
'./object-utils',
'./MutableObject',
'./RootRegistry',
'./RootObjectProvider'
'./MutableObject'
], function (
_,
utils,
MutableObject,
RootRegistry,
RootObjectProvider
MutableObject
) {
@ -44,8 +40,16 @@ define([
function ObjectAPI() {
this.providers = {};
this.rootRegistry = new RootRegistry();
this.rootProvider = new RootObjectProvider(this.rootRegistry);
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) {
@ -139,14 +143,29 @@ define([
/**
* Add a root-level object.
* @param {module:openmct.ObjectAPI~Identifier|function} an array of
* identifiers for root level objects, or a function that returns a
* promise for an identifier or an array of root level objects.
* @param {module:openmct.DomainObject} domainObject the root-level object
* to add.
* @method addRoot
* @memberof module:openmct.ObjectAPI#
*/
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
);
});
};
/**

View File

@ -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;
});

View File

@ -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;
});

View File

@ -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());
});
});
});

View File

@ -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());
});
});
});

View File

@ -72,7 +72,6 @@ define([
'../platform/features/conductor-v2/utcTimeSystem/bundle',
'../platform/features/imagery/bundle',
'../platform/features/layout/bundle',
'../platform/features/my-items/bundle',
'../platform/features/pages/bundle',
'../platform/features/plot/bundle',
'../platform/features/static-markup/bundle',