mirror of
https://github.com/nasa/openmct.git
synced 2025-01-26 22:29:34 +00:00
[Framework] Add bundle resolver; normalize initialization
Simplify the extension initializer by putting each phase's responsibilities into a specific class. WTD-518.
This commit is contained in:
parent
d8eb72621b
commit
306d8ae9db
@ -108,6 +108,12 @@ define(
|
|||||||
getLogName: function () {
|
getLogName: function () {
|
||||||
return logName;
|
return logName;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param category
|
||||||
|
* @memberof Bundle#
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
getExtensions: function (category) {
|
getExtensions: function (category) {
|
||||||
var extensions = definition.extensions[category] || [];
|
var extensions = definition.extensions[category] || [];
|
||||||
|
|
||||||
@ -115,6 +121,10 @@ define(
|
|||||||
return new Extension(self, category, extDefinition);
|
return new Extension(self, category, extDefinition);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* @memberof Bundle#
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
getExtensionCategories: function () {
|
getExtensionCategories: function () {
|
||||||
return Object.keys(definition.extensions);
|
return Object.keys(definition.extensions);
|
||||||
},
|
},
|
||||||
|
73
platform/framework/src/BundleResolver.js
Normal file
73
platform/framework/src/BundleResolver.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*global define,Promise*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module defining BundleResolver. Created by vwoeltje on 11/4/14.
|
||||||
|
*/
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function BundleResolver(extensionResolver) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Object.<string, object[]>[]} resolvedBundles
|
||||||
|
* @returns {Object.<string, object[]>}
|
||||||
|
*/
|
||||||
|
function mergeResolvedBundles(resolvedBundles) {
|
||||||
|
var result = {};
|
||||||
|
|
||||||
|
resolvedBundles.forEach(function (resolved) {
|
||||||
|
Object.keys(resolved).forEach(function (k) {
|
||||||
|
result[k] = (result[k] || []).concat(resolved[k]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveBundle(bundle) {
|
||||||
|
var categories = bundle.getExtensionCategories(),
|
||||||
|
result = {};
|
||||||
|
|
||||||
|
function resolveExtension(extension) {
|
||||||
|
var category = extension.getCategory();
|
||||||
|
|
||||||
|
function push(resolved) {
|
||||||
|
result[category].push(resolved);
|
||||||
|
}
|
||||||
|
|
||||||
|
return extensionResolver.resolve(extension).then(push);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveCategory(category) {
|
||||||
|
result[category] = [];
|
||||||
|
return Promise.all(
|
||||||
|
bundle.getExtensions(category).map(resolveExtension)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function giveResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(categories.map(resolveCategory))
|
||||||
|
.then(giveResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
resolveBundles: function (bundles) {
|
||||||
|
return Promise.all(bundles.map(resolveBundle))
|
||||||
|
.then(mergeResolvedBundles);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return BundleResolver;
|
||||||
|
}
|
||||||
|
);
|
@ -25,6 +25,10 @@ define(
|
|||||||
return category + "[" + name + "]";
|
return category + "[" + name + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function identifyCategory(category) {
|
||||||
|
return category + Constants.EXTENSION_SUFFIX;
|
||||||
|
}
|
||||||
|
|
||||||
function echo() {
|
function echo() {
|
||||||
return arguments.slice;
|
return arguments.slice;
|
||||||
}
|
}
|
||||||
@ -50,7 +54,7 @@ define(
|
|||||||
app.factory(name, names.concat([echo]));
|
app.factory(name, names.concat([echo]));
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerExtensions(category, extensions) {
|
function registerExtensionsForCategory(category, extensions) {
|
||||||
var names = [];
|
var names = [];
|
||||||
|
|
||||||
function registerExtension(extension, index) {
|
function registerExtension(extension, index) {
|
||||||
@ -83,10 +87,19 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function registerExtensionGroup(extensionGroup) {
|
||||||
|
Object.keys(extensionGroup).forEach(function (category) {
|
||||||
|
registerExtensionsForCategory(
|
||||||
|
category,
|
||||||
|
extensionGroup[category]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
customRegistrars = customRegistrars || {};
|
customRegistrars = customRegistrars || {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
registerExtensions: registerExtensions
|
registerExtensions: registerExtensionGroup
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ define(
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {BundleLoader} loader
|
* @param {BundleLoader} loader
|
||||||
* @param {ExtensionResolver} resolver
|
* @param {BundleResolver} resolver
|
||||||
* @param {ExtensionRegistrar} registrar
|
* @param {ExtensionRegistrar} registrar
|
||||||
* @param {ApplicationBootstrapper} bootstrapper
|
* @param {ApplicationBootstrapper} bootstrapper
|
||||||
*/
|
*/
|
||||||
@ -29,20 +29,11 @@ define(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param bundles
|
* @param {Bundle[]} bundles
|
||||||
* @returns {Object.<string, object[]>} an object mapping
|
* @returns {Object.<string, object[]>} an object mapping
|
||||||
*/
|
*/
|
||||||
function resolveExtensions(bundles) {
|
function resolveExtensions(bundles) {
|
||||||
var resolvedExtensions = {};
|
return resolver.resolveBundles(bundles);
|
||||||
|
|
||||||
|
|
||||||
function resolveExtensionsForBundle(bundle) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promises.all(bundles.map(resolveExtensionsForBundle)).then(function () {
|
|
||||||
return resolvedExtensions;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadBundles(bundleList) {
|
function loadBundles(bundleList) {
|
||||||
@ -51,10 +42,11 @@ define(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
runApplication: function (bundleList) {
|
runApplication: function (bundleList) {
|
||||||
return loadBundles()
|
return loader.loadBundles(bundleList)
|
||||||
.then(resolveExtensions)
|
.then(resolver.resolveBundles)
|
||||||
.then(registerExtensions)
|
.then(registrar.registerExtensions)
|
||||||
.then(bootstrapApplication);
|
.then(bootstrapper.bootstrapApplication);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user