mirror of
https://github.com/nasa/openmct.git
synced 2025-02-18 16:40:58 +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:
parent
3682eb73cb
commit
08ff75c9c0
@ -80,6 +80,9 @@ define(
|
||||
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]);
|
||||
}
|
||||
);
|
@ -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"
|
||||
function registerRoute(extension) {
|
||||
var route = Object.create(extension);
|
||||
@ -93,6 +116,7 @@ define(
|
||||
// name of the extension category to be handled, and the value
|
||||
// is the function which handles it.
|
||||
return {
|
||||
constants: mapUpon(registerConstant),
|
||||
routes: mapUpon(registerRoute),
|
||||
directives: mapUpon(new CustomRegistrar("directive")),
|
||||
controllers: mapUpon(new CustomRegistrar("controller")),
|
||||
|
@ -156,6 +156,9 @@ define(
|
||||
}
|
||||
|
||||
function registerExtensionGroup(extensionGroup) {
|
||||
// Announce we're entering a new phase
|
||||
$log.info("Registering extensions...");
|
||||
|
||||
// Register all declared extensions by category
|
||||
Object.keys(extensionGroup).forEach(function (category) {
|
||||
registerExtensionsForCategory(
|
||||
|
@ -26,10 +26,10 @@ define(
|
||||
*/
|
||||
function PartialConstructor(Constructor) {
|
||||
|
||||
return function () { // Bind services
|
||||
function OuterConstructor() { // Bind services
|
||||
var dependencies = Array.prototype.slice.call(arguments);
|
||||
|
||||
return function () { // Bind everything else
|
||||
function InnerConstructor() { // Bind everything else
|
||||
var other = Array.prototype.slice.call(arguments),
|
||||
instance = Object.create(Constructor.prototype);
|
||||
|
||||
@ -41,7 +41,16 @@ define(
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
// Copy properties from original constructor
|
||||
Object.keys(Constructor).forEach(function (k) {
|
||||
InnerConstructor[k] = Constructor[k];
|
||||
});
|
||||
|
||||
return InnerConstructor;
|
||||
};
|
||||
|
||||
return OuterConstructor;
|
||||
}
|
||||
|
||||
return PartialConstructor;
|
||||
|
@ -31,12 +31,21 @@ define(
|
||||
} :
|
||||
Object.create(impl);
|
||||
|
||||
Object.keys(definition).forEach(function (k) {
|
||||
result[k] = definition[k];
|
||||
// Copy over static properties
|
||||
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.info("Loaded " + extension.getLogName());
|
||||
$log.info("Resolved " + extension.getLogName());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user