mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 16:36:13 +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
|
||||
*/
|
||||
function Extension(bundle, category, definition) {
|
||||
var logName = category;
|
||||
var logName = category,
|
||||
extensionDefinition = Object.create(definition);
|
||||
|
||||
// Build up the log-friendly name for this bundle
|
||||
if (definition.key || definition.name) {
|
||||
@ -42,6 +43,9 @@ define(
|
||||
}
|
||||
logName += " from " + bundle.getLogName();
|
||||
|
||||
// Attach bundle metadata
|
||||
extensionDefinition.bundle = bundle.getDefinition();
|
||||
|
||||
return {
|
||||
/**
|
||||
* @returns {string}
|
||||
@ -98,7 +102,7 @@ define(
|
||||
* @returns {ExtensionDefinition}
|
||||
*/
|
||||
getDefinition: function () {
|
||||
return definition;
|
||||
return extensionDefinition;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -12,11 +12,11 @@ define(
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function ExtensionRegistrar(app, $log) {
|
||||
function ExtensionRegistrar(app, customRegistrars, $log) {
|
||||
// Track which extension categories have already been registered.
|
||||
// Exceptions will be thrown if the same extension category is
|
||||
// registered twice.
|
||||
var registeredCategories = {};
|
||||
var registeredCategories = {},
|
||||
|
||||
function identify(category, extension, index) {
|
||||
var name = extension.key ?
|
||||
@ -68,13 +68,18 @@ define(
|
||||
category,
|
||||
" more than once. Ignoring all but first set."
|
||||
].join(""));
|
||||
} else if (customRegistrars[category]) {
|
||||
return customRegistrars[category](extensions);
|
||||
} else {
|
||||
extensions.forEach(registerExtension);
|
||||
registerExtensionArraysForCategory(category, names);
|
||||
registeredCategories[category] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
customRegistrars = customRegistrars || {};
|
||||
|
||||
return {
|
||||
registerExtensions: registerExtensions
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user