mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 06:08:11 +00:00
[Framework] Bring in changes from sandbox
Bring in changes from 'sandbox' branch. These include: * Reconfiguring require's baseUrl such that relative paths work as expected in define call dependencies. Previously this only worked as expected in the framework bundle, since data-main points there. * Add support for a 'constants' category of extension, to define application constants from bundles. This allows services to treat static values (such as persistence URIs) as injectable dependencies. * Various assurances that properties from extension definitions will be exposed upon resolved implementations, even after partial construction. WTD-572.
This commit is contained in:
@ -80,6 +80,9 @@ define(
|
|||||||
initializer.runApplication(Constants.BUNDLE_LISTING_FILE);
|
initializer.runApplication(Constants.BUNDLE_LISTING_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reconfigure base url, since bundle paths will all be relative
|
||||||
|
// to the root now.
|
||||||
|
requirejs.config({ "baseUrl": "" });
|
||||||
injector.invoke(['$http', '$log', initializeApplication]);
|
injector.invoke(['$http', '$log', initializeApplication]);
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -49,6 +49,29 @@ define(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function registerConstant(extension) {
|
||||||
|
var key = extension.key,
|
||||||
|
value = extension.value;
|
||||||
|
|
||||||
|
if (typeof key === "string" && value !== undefined) {
|
||||||
|
$log.info([
|
||||||
|
"Registering constant: ",
|
||||||
|
key,
|
||||||
|
" with value ",
|
||||||
|
value
|
||||||
|
].join(""));
|
||||||
|
app.constant(key, value);
|
||||||
|
} else {
|
||||||
|
$log.warn([
|
||||||
|
"Cannot register constant ",
|
||||||
|
key,
|
||||||
|
" with value ",
|
||||||
|
value
|
||||||
|
].join(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Custom registration function for extensions of category "route"
|
// Custom registration function for extensions of category "route"
|
||||||
function registerRoute(extension) {
|
function registerRoute(extension) {
|
||||||
var route = Object.create(extension);
|
var route = Object.create(extension);
|
||||||
@ -93,6 +116,7 @@ define(
|
|||||||
// name of the extension category to be handled, and the value
|
// name of the extension category to be handled, and the value
|
||||||
// is the function which handles it.
|
// is the function which handles it.
|
||||||
return {
|
return {
|
||||||
|
constants: mapUpon(registerConstant),
|
||||||
routes: mapUpon(registerRoute),
|
routes: mapUpon(registerRoute),
|
||||||
directives: mapUpon(new CustomRegistrar("directive")),
|
directives: mapUpon(new CustomRegistrar("directive")),
|
||||||
controllers: mapUpon(new CustomRegistrar("controller")),
|
controllers: mapUpon(new CustomRegistrar("controller")),
|
||||||
|
@ -156,6 +156,9 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerExtensionGroup(extensionGroup) {
|
function registerExtensionGroup(extensionGroup) {
|
||||||
|
// Announce we're entering a new phase
|
||||||
|
$log.info("Registering extensions...");
|
||||||
|
|
||||||
// Register all declared extensions by category
|
// Register all declared extensions by category
|
||||||
Object.keys(extensionGroup).forEach(function (category) {
|
Object.keys(extensionGroup).forEach(function (category) {
|
||||||
registerExtensionsForCategory(
|
registerExtensionsForCategory(
|
||||||
|
@ -26,10 +26,10 @@ define(
|
|||||||
*/
|
*/
|
||||||
function PartialConstructor(Constructor) {
|
function PartialConstructor(Constructor) {
|
||||||
|
|
||||||
return function () { // Bind services
|
function OuterConstructor() { // Bind services
|
||||||
var dependencies = Array.prototype.slice.call(arguments);
|
var dependencies = Array.prototype.slice.call(arguments);
|
||||||
|
|
||||||
return function () { // Bind everything else
|
function InnerConstructor() { // Bind everything else
|
||||||
var other = Array.prototype.slice.call(arguments),
|
var other = Array.prototype.slice.call(arguments),
|
||||||
instance = Object.create(Constructor.prototype);
|
instance = Object.create(Constructor.prototype);
|
||||||
|
|
||||||
@ -41,7 +41,16 @@ define(
|
|||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Copy properties from original constructor
|
||||||
|
Object.keys(Constructor).forEach(function (k) {
|
||||||
|
InnerConstructor[k] = Constructor[k];
|
||||||
|
});
|
||||||
|
|
||||||
|
return InnerConstructor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return OuterConstructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PartialConstructor;
|
return PartialConstructor;
|
||||||
|
@ -31,12 +31,21 @@ define(
|
|||||||
} :
|
} :
|
||||||
Object.create(impl);
|
Object.create(impl);
|
||||||
|
|
||||||
Object.keys(definition).forEach(function (k) {
|
// Copy over static properties
|
||||||
result[k] = definition[k];
|
Object.keys(impl).forEach(function (k) {
|
||||||
|
result[k] = impl[k];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Copy over definition
|
||||||
|
Object.keys(definition).forEach(function (k) {
|
||||||
|
if (result[k] === undefined) {
|
||||||
|
result[k] = definition[k];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
result.definition = definition;
|
||||||
|
|
||||||
// Log that this load was successful
|
// Log that this load was successful
|
||||||
$log.info("Loaded " + extension.getLogName());
|
$log.info("Resolved " + extension.getLogName());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user