mirror of
https://github.com/nasa/openmct.git
synced 2025-06-01 23:20:50 +00:00
[API] Load bundles from imperative registry
This commit is contained in:
parent
65fb5ab2a5
commit
a39e8e44f0
@ -55,11 +55,15 @@ define([
|
|||||||
this.$log = $log;
|
this.$log = $log;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameworkLayer.prototype.initializeApplication = function (angular, logLevel) {
|
FrameworkLayer.prototype.initializeApplication = function (
|
||||||
|
angular,
|
||||||
|
legacyRegistry,
|
||||||
|
logLevel
|
||||||
|
) {
|
||||||
var $http = this.$http,
|
var $http = this.$http,
|
||||||
$log = this.$log,
|
$log = this.$log,
|
||||||
app = angular.module(Constants.MODULE_NAME, ["ngRoute"]),
|
app = angular.module(Constants.MODULE_NAME, ["ngRoute"]),
|
||||||
loader = new BundleLoader($http, $log),
|
loader = new BundleLoader($http, $log, legacyRegistry),
|
||||||
resolver = new BundleResolver(
|
resolver = new BundleResolver(
|
||||||
new ExtensionResolver(
|
new ExtensionResolver(
|
||||||
new ImplementationLoader(require),
|
new ImplementationLoader(require),
|
||||||
|
@ -56,7 +56,7 @@ define(
|
|||||||
function Main() {
|
function Main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Main.prototype.run = function () {
|
Main.prototype.run = function (legacyRegistry) {
|
||||||
// Get a reference to Angular's injector, so we can get $http and $log
|
// Get a reference to Angular's injector, so we can get $http and $log
|
||||||
// services, which are useful to the framework layer.
|
// services, which are useful to the framework layer.
|
||||||
var injector = angular.injector(['ng']);
|
var injector = angular.injector(['ng']);
|
||||||
@ -74,7 +74,7 @@ define(
|
|||||||
// to the root now.
|
// to the root now.
|
||||||
requirejs.config({"baseUrl": ""});
|
requirejs.config({"baseUrl": ""});
|
||||||
injector.instantiate(['$http', '$log', FrameworkLayer])
|
injector.instantiate(['$http', '$log', FrameworkLayer])
|
||||||
.initializeApplication(angular, logLevel());
|
.initializeApplication(angular, legacyRegistry, logLevel());
|
||||||
};
|
};
|
||||||
|
|
||||||
return Main;
|
return Main;
|
||||||
|
@ -44,9 +44,10 @@ define(
|
|||||||
* @param $http Angular's HTTP requester
|
* @param $http Angular's HTTP requester
|
||||||
* @param $log Angular's logging service
|
* @param $log Angular's logging service
|
||||||
*/
|
*/
|
||||||
function BundleLoader($http, $log) {
|
function BundleLoader($http, $log, legacyRegistry) {
|
||||||
this.$http = $http;
|
this.$http = $http;
|
||||||
this.$log = $log;
|
this.$log = $log;
|
||||||
|
this.legacyRegistry = legacyRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,6 +97,13 @@ define(
|
|||||||
// Load an individual bundle, as a Bundle object.
|
// Load an individual bundle, as a Bundle object.
|
||||||
// Returns undefined if the definition could not be loaded.
|
// Returns undefined if the definition could not be loaded.
|
||||||
function loadBundle(bundlePath) {
|
function loadBundle(bundlePath) {
|
||||||
|
if (this.legacyRegistry.contains(bundlePath)) {
|
||||||
|
return Promise.resolve(new Bundle(
|
||||||
|
bundlePath,
|
||||||
|
this.legacyRegistry.get(bundlePath)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
return loadBundleDefinition(bundlePath).then(function (definition) {
|
return loadBundleDefinition(bundlePath).then(function (definition) {
|
||||||
return definition && (new Bundle(bundlePath, definition));
|
return definition && (new Bundle(bundlePath, definition));
|
||||||
});
|
});
|
||||||
@ -104,7 +112,9 @@ define(
|
|||||||
// Load all named bundles from the array, returned as an array
|
// Load all named bundles from the array, returned as an array
|
||||||
// of Bundle objects.
|
// of Bundle objects.
|
||||||
function loadBundlesFromArray(bundleArray) {
|
function loadBundlesFromArray(bundleArray) {
|
||||||
var bundlePromises = bundleArray.map(loadBundle);
|
var bundlePromises = this.legacyRegistry.list()
|
||||||
|
.concat(bundleArray)
|
||||||
|
.map(loadBundle);
|
||||||
|
|
||||||
return Promise.all(bundlePromises)
|
return Promise.all(bundlePromises)
|
||||||
.then(filterBundles);
|
.then(filterBundles);
|
||||||
@ -117,8 +127,8 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Array.isArray(bundles) ? loadBundlesFromArray(bundles) :
|
return Array.isArray(bundles) ? loadBundlesFromArray(bundles) :
|
||||||
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
|
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
|
||||||
Promise.reject(new Error(INVALID_ARGUMENT_MESSAGE));
|
Promise.reject(new Error(INVALID_ARGUMENT_MESSAGE));
|
||||||
};
|
};
|
||||||
|
|
||||||
return BundleLoader;
|
return BundleLoader;
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
define(function () {
|
define(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function BundleRegistry() {
|
function BundleRegistry() {
|
||||||
this.bundles = {};
|
this.bundles = {};
|
||||||
}
|
}
|
||||||
@ -38,5 +40,9 @@ define(function () {
|
|||||||
return this.bundles[path];
|
return this.bundles[path];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BundleRegistry.prototype.list = function () {
|
||||||
|
return Object.keys(this.bundles);
|
||||||
|
};
|
||||||
|
|
||||||
return BundleRegistry;
|
return BundleRegistry;
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user