mirror of
https://github.com/nasa/openmct.git
synced 2025-04-12 21:53:07 +00:00
[Framework] Handle empty extension sets
Satisfy dependencies on empty extension sets when necessary; extensions which depend on extension categories which do not exist then get an empty array. WTD-518.
This commit is contained in:
parent
ff9682c40c
commit
033ecec295
@ -101,6 +101,55 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a declared dependency looks like a dependency on
|
||||
// an extension category (e.g. is suffixed by [])
|
||||
function isExtensionDependency(dependency) {
|
||||
var index = dependency.indexOf(
|
||||
Constants.EXTENSION_SUFFIX,
|
||||
dependency.length - Constants.EXTENSION_SUFFIX.length
|
||||
);
|
||||
return index !== -1;
|
||||
}
|
||||
|
||||
function findEmptyExtensionDependencies(extensionGroup) {
|
||||
var needed = {},
|
||||
categories = Object.keys(extensionGroup),
|
||||
allExtensions = [];
|
||||
|
||||
// Build up an array of all extensions
|
||||
categories.forEach(function (category) {
|
||||
allExtensions =
|
||||
allExtensions.concat(extensionGroup[category]);
|
||||
});
|
||||
|
||||
// Track all extension dependencies exposed therefrom
|
||||
allExtensions.forEach(function (extension) {
|
||||
(extension.depends || []).filter(
|
||||
isExtensionDependency
|
||||
).forEach(function (dependency) {
|
||||
needed[dependency] = true;
|
||||
});
|
||||
});
|
||||
|
||||
// Remove categories which have been provided
|
||||
categories.forEach(function (category) {
|
||||
var dependency = category + Constants.EXTENSION_SUFFIX;
|
||||
delete needed[dependency];
|
||||
});
|
||||
|
||||
return Object.keys(needed);
|
||||
}
|
||||
|
||||
|
||||
function registerEmptyDependencies(extensionGroup) {
|
||||
findEmptyExtensionDependencies(
|
||||
extensionGroup
|
||||
).forEach(function (name) {
|
||||
$log.info("Registering empty extension category " + name);
|
||||
app.factory(name, [staticFunction([])]);
|
||||
});
|
||||
}
|
||||
|
||||
function registerExtensionGroup(extensionGroup) {
|
||||
Object.keys(extensionGroup).forEach(function (category) {
|
||||
registerExtensionsForCategory(
|
||||
@ -109,6 +158,8 @@ define(
|
||||
);
|
||||
});
|
||||
|
||||
registerEmptyDependencies(extensionGroup);
|
||||
|
||||
// Return the application to which these extensions
|
||||
// have been registered
|
||||
return app;
|
||||
|
Loading…
x
Reference in New Issue
Block a user