[API] Load bundles from imperative registry

This commit is contained in:
Victor Woeltjen 2016-01-06 11:22:44 -08:00
parent 65fb5ab2a5
commit a39e8e44f0
4 changed files with 28 additions and 8 deletions

View File

@ -55,11 +55,15 @@ define([
this.$log = $log;
}
FrameworkLayer.prototype.initializeApplication = function (angular, logLevel) {
FrameworkLayer.prototype.initializeApplication = function (
angular,
legacyRegistry,
logLevel
) {
var $http = this.$http,
$log = this.$log,
app = angular.module(Constants.MODULE_NAME, ["ngRoute"]),
loader = new BundleLoader($http, $log),
loader = new BundleLoader($http, $log, legacyRegistry),
resolver = new BundleResolver(
new ExtensionResolver(
new ImplementationLoader(require),

View File

@ -56,7 +56,7 @@ define(
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
// services, which are useful to the framework layer.
var injector = angular.injector(['ng']);
@ -74,7 +74,7 @@ define(
// to the root now.
requirejs.config({"baseUrl": ""});
injector.instantiate(['$http', '$log', FrameworkLayer])
.initializeApplication(angular, logLevel());
.initializeApplication(angular, legacyRegistry, logLevel());
};
return Main;

View File

@ -44,9 +44,10 @@ define(
* @param $http Angular's HTTP requester
* @param $log Angular's logging service
*/
function BundleLoader($http, $log) {
function BundleLoader($http, $log, legacyRegistry) {
this.$http = $http;
this.$log = $log;
this.legacyRegistry = legacyRegistry;
}
/**
@ -96,6 +97,13 @@ define(
// Load an individual bundle, as a Bundle object.
// Returns undefined if the definition could not be loaded.
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 definition && (new Bundle(bundlePath, definition));
});
@ -104,7 +112,9 @@ define(
// Load all named bundles from the array, returned as an array
// of Bundle objects.
function loadBundlesFromArray(bundleArray) {
var bundlePromises = bundleArray.map(loadBundle);
var bundlePromises = this.legacyRegistry.list()
.concat(bundleArray)
.map(loadBundle);
return Promise.all(bundlePromises)
.then(filterBundles);
@ -117,8 +127,8 @@ define(
}
return Array.isArray(bundles) ? loadBundlesFromArray(bundles) :
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
Promise.reject(new Error(INVALID_ARGUMENT_MESSAGE));
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
Promise.reject(new Error(INVALID_ARGUMENT_MESSAGE));
};
return BundleLoader;

View File

@ -22,6 +22,8 @@
/*global define*/
define(function () {
'use strict';
function BundleRegistry() {
this.bundles = {};
}
@ -38,5 +40,9 @@ define(function () {
return this.bundles[path];
};
BundleRegistry.prototype.list = function () {
return Object.keys(this.bundles);
};
return BundleRegistry;
});