From 0e6f419678788d67fb835c033f73518621c4040d Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 4 Nov 2014 15:27:10 -0800 Subject: [PATCH] [Framework] Allow controller registration Add tweaks in framework which fix errors which were preventing controller registration. This includes maintaining the type of controllers as functions, even after decorating with information from the extension. WTD-518. --- platform/framework/src/Bundle.js | 2 +- platform/framework/src/CustomRegistrars.js | 7 ++++--- platform/framework/src/Extension.js | 11 ++++++++++- platform/framework/src/ExtensionRegistrar.js | 7 +++++-- platform/framework/src/ExtensionResolver.js | 6 +++++- platform/framework/src/ImplementationLoader.js | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/platform/framework/src/Bundle.js b/platform/framework/src/Bundle.js index fe38c5dc8e..6ea29289df 100644 --- a/platform/framework/src/Bundle.js +++ b/platform/framework/src/Bundle.js @@ -38,7 +38,7 @@ define( // Utility function for resolving paths in this bundle function resolvePath(elements) { - return path.concat(elements || []).join(Constants.SEPARATOR); + return [path].concat(elements || []).join(Constants.SEPARATOR); } // Override defaults with specifics from bundle definition diff --git a/platform/framework/src/CustomRegistrars.js b/platform/framework/src/CustomRegistrars.js index 6fea41a986..f366c4465f 100644 --- a/platform/framework/src/CustomRegistrars.js +++ b/platform/framework/src/CustomRegistrars.js @@ -20,13 +20,14 @@ define( var key = extension.key, dependencies = extension.depends || []; + if (!key) { $log.warn([ "Cannot register ", angularFunction, - ", ", + " ", index, - "no key specified. ", + ", no key specified. ", JSON.stringify(extension) ].join("")); } else { @@ -35,7 +36,7 @@ define( angularFunction, ": ", key - ]); + ].join("")); app[angularFunction]( key, dependencies.concat([extension]) diff --git a/platform/framework/src/Extension.js b/platform/framework/src/Extension.js index 567ef88732..b1a4b340ec 100644 --- a/platform/framework/src/Extension.js +++ b/platform/framework/src/Extension.js @@ -3,6 +3,8 @@ define( [], function () { + "use strict"; + /** * An extension's plain JSON definition. * @@ -32,7 +34,7 @@ define( */ function Extension(bundle, category, definition) { var logName = category, - extensionDefinition = Object.create(definition); + extensionDefinition = {}; // Build up the log-friendly name for this bundle if (definition.key || definition.name) { @@ -40,9 +42,16 @@ define( logName += definition.key || ""; logName += (definition.key && definition.name) ? " " : ""; logName += definition.name || ""; + logName += ")"; } logName += " from " + bundle.getLogName(); + // Copy over definition. This allows us to attach the bundle + // definition without modifying the original definition object. + Object.keys(definition).forEach(function (k) { + extensionDefinition[k] = definition[k]; + }); + // Attach bundle metadata extensionDefinition.bundle = bundle.getDefinition(); diff --git a/platform/framework/src/ExtensionRegistrar.js b/platform/framework/src/ExtensionRegistrar.js index cff9819f6c..8159476bce 100644 --- a/platform/framework/src/ExtensionRegistrar.js +++ b/platform/framework/src/ExtensionRegistrar.js @@ -36,7 +36,7 @@ define( // Utility function; create the second argument for Angular's // .service service registration method (an array containing // both dependencies and a factory method for the service.) - function makeServiceArgument(extension) { + function makeServiceArgument(category, extension) { var dependencies = extension.depends || [], factory = (typeof extension === 'function') ? new PartialConstructor(extension) : @@ -59,7 +59,10 @@ define( // Track individual extension names as-registered names.push(name); - app.factory(name, makeServiceArgument(extension)); + app.factory( + name, + makeServiceArgument(category, extension) + ); } if (registeredCategories[category]) { diff --git a/platform/framework/src/ExtensionResolver.js b/platform/framework/src/ExtensionResolver.js index 8572175ca0..4c686355e1 100644 --- a/platform/framework/src/ExtensionResolver.js +++ b/platform/framework/src/ExtensionResolver.js @@ -25,7 +25,11 @@ define( // Attach values from the object definition to the // loaded implementation. function attachDefinition(impl) { - var result = Object.create(impl); + var result = (typeof impl === 'function') ? + function () { + return impl.apply({}, arguments); + } : + Object.create(impl); Object.keys(definition).forEach(function (k) { result[k] = definition[k]; diff --git a/platform/framework/src/ImplementationLoader.js b/platform/framework/src/ImplementationLoader.js index 6d864fb054..cba083e373 100644 --- a/platform/framework/src/ImplementationLoader.js +++ b/platform/framework/src/ImplementationLoader.js @@ -19,7 +19,7 @@ define( function ImplementationLoader(require) { function loadModule(path) { return new Promise(function (fulfill, reject) { - require(path, fulfill, reject); + require([path], fulfill, reject); }); }