mirror of
https://github.com/nasa/openmct.git
synced 2025-05-13 22:13:18 +00:00
[Framework] Intermediary commit; registration phase
Continue implementation of registration phase of framework layer. Begin adding some custom registration behavior for specific Angular concepts, such as services and directives. WTD-518.
This commit is contained in:
parent
650969d9c5
commit
00de789f5e
56
platform/framework/src/CustomRegistrars.js
Normal file
56
platform/framework/src/CustomRegistrars.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*global define,Promise*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module defining CustomRegistrars. Created by vwoeltje on 11/3/14.
|
||||||
|
*/
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles registration of a few specific extension types that are
|
||||||
|
* understood natively by Angular. This includes services and
|
||||||
|
* directives.
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function CustomRegistrars(app, $log) {
|
||||||
|
function CustomRegistrar(angularFunction) {
|
||||||
|
function registerExtension(extension, index) {
|
||||||
|
var key = extension.key,
|
||||||
|
dependencies = extension.depends || [];
|
||||||
|
|
||||||
|
if (!key) {
|
||||||
|
$log.warn([
|
||||||
|
"Cannot register ",
|
||||||
|
angularFunction,
|
||||||
|
", ",
|
||||||
|
index,
|
||||||
|
"no key specified. ",
|
||||||
|
JSON.stringify(extension)
|
||||||
|
].join(""));
|
||||||
|
} else {
|
||||||
|
$log.info([
|
||||||
|
"Registering ",
|
||||||
|
angularFunction,
|
||||||
|
": ",
|
||||||
|
key
|
||||||
|
]);
|
||||||
|
app[angularFunction](
|
||||||
|
key,
|
||||||
|
dependencies.concat([extension])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
services: function (extensions) {
|
||||||
|
return extensions.map(registerExtension);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return CustomRegistrars;
|
||||||
|
}
|
||||||
|
);
|
@ -31,7 +31,8 @@ define(
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Extension(bundle, category, definition) {
|
function Extension(bundle, category, definition) {
|
||||||
var logName = category;
|
var logName = category,
|
||||||
|
extensionDefinition = Object.create(definition);
|
||||||
|
|
||||||
// Build up the log-friendly name for this bundle
|
// Build up the log-friendly name for this bundle
|
||||||
if (definition.key || definition.name) {
|
if (definition.key || definition.name) {
|
||||||
@ -42,6 +43,9 @@ define(
|
|||||||
}
|
}
|
||||||
logName += " from " + bundle.getLogName();
|
logName += " from " + bundle.getLogName();
|
||||||
|
|
||||||
|
// Attach bundle metadata
|
||||||
|
extensionDefinition.bundle = bundle.getDefinition();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@ -98,7 +102,7 @@ define(
|
|||||||
* @returns {ExtensionDefinition}
|
* @returns {ExtensionDefinition}
|
||||||
*/
|
*/
|
||||||
getDefinition: function () {
|
getDefinition: function () {
|
||||||
return definition;
|
return extensionDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -12,11 +12,11 @@ define(
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function ExtensionRegistrar(app, $log) {
|
function ExtensionRegistrar(app, customRegistrars, $log) {
|
||||||
// Track which extension categories have already been registered.
|
// Track which extension categories have already been registered.
|
||||||
// Exceptions will be thrown if the same extension category is
|
// Exceptions will be thrown if the same extension category is
|
||||||
// registered twice.
|
// registered twice.
|
||||||
var registeredCategories = {};
|
var registeredCategories = {},
|
||||||
|
|
||||||
function identify(category, extension, index) {
|
function identify(category, extension, index) {
|
||||||
var name = extension.key ?
|
var name = extension.key ?
|
||||||
@ -68,13 +68,18 @@ define(
|
|||||||
category,
|
category,
|
||||||
" more than once. Ignoring all but first set."
|
" more than once. Ignoring all but first set."
|
||||||
].join(""));
|
].join(""));
|
||||||
|
} else if (customRegistrars[category]) {
|
||||||
|
return customRegistrars[category](extensions);
|
||||||
} else {
|
} else {
|
||||||
extensions.forEach(registerExtension);
|
extensions.forEach(registerExtension);
|
||||||
registerExtensionArraysForCategory(category, names);
|
registerExtensionArraysForCategory(category, names);
|
||||||
registeredCategories[category] = true;
|
registeredCategories[category] = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
customRegistrars = customRegistrars || {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
registerExtensions: registerExtensions
|
registerExtensions: registerExtensions
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user