[Framework] Begin work on extension resolution

Begin work on extension resolution phase of
the framework layer. WTD-518.

Introduce an implementation loader which wraps
RequireJS, and a skeleton class for extension
resolution.
This commit is contained in:
Victor Woeltjen 2014-11-03 09:44:16 -08:00
parent 0e82250c84
commit a940d1a460
4 changed files with 79 additions and 0 deletions

View File

@ -95,6 +95,9 @@ define(
return new Extension(self, category, extDefinition); return new Extension(self, category, extDefinition);
}); });
}, },
getExtensionCategories: function () {
return Object.keys(definition.extensions);
},
/** /**
* *
* @memberof Bundle# * @memberof Bundle#

View File

@ -48,6 +48,13 @@ define(
getCategory: function () { getCategory: function () {
return category; return category;
}, },
/**
* Check whether or not this
* @returns {boolean}
*/
hasImplementation: function () {
return definition.implementation !== undefined;
},
/** /**
* Get the path to the AMD module which implements this * Get the path to the AMD module which implements this
* extension. Will return undefined if there is no * extension. Will return undefined if there is no

View File

@ -0,0 +1,23 @@
/*global define,Promise*/
/**
* Module defining ExtensionResolver. Created by vwoeltje on 11/3/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function ExtensionResolver(require) {
return {
};
}
return ExtensionResolver;
}
);

View File

@ -0,0 +1,46 @@
/*global define,Promise*/
/**
* Module defining ImplementationLoader. Created by vwoeltje on 11/3/14.
*/
define(
[],
function () {
"use strict";
/**
* Responsible for loading extension implementations
* (AMD modules.) Acts as a wrapper around RequireJS to
* provide a promise-like API.
* @constructor
* @param {*} require RequireJS, or an object with similar API
* @param {*} $log Angular's logging service
*/
function ImplementationLoader(require) {
function loadModule(path) {
return new Promise(function (fulfill, reject) {
require(path, fulfill, reject);
});
}
return {
/**
* Load an extension's implementation; or, equivalently,
* load an AMD module. This is fundamentally similar
* to a call to RequireJS, except that the result is
* wrapped in a promise. The promise will be fulfilled
* with the loaded module, or rejected with the error
* reported by Require.
*
* @method
* @memberof ImplementationLoader#
* @param {string} path the path to the module to load
* @returns {Promise} a promise for the specified module.
*/
load: loadModule
};
}
return ImplementationLoader;
}
);