diff --git a/platform/framework/src/register/CustomRegistrars.js b/platform/framework/src/register/CustomRegistrars.js index 9c3fc0a225..9f6717367a 100644 --- a/platform/framework/src/register/CustomRegistrars.js +++ b/platform/framework/src/register/CustomRegistrars.js @@ -72,6 +72,21 @@ define( } + // Custom registration function for extensions of category "runs" + function registerRun(extension) { + if (typeof extension === 'function') { + // Prepend dependencies, and schedule to run + app.run((extension.depends || []).concat([extension])); + } else { + // If it's not a function, no implementation was given + $log.warn([ + "Cannot register run extension from ", + (extension.bundle || {}).path, + "; no implementation." + ].join("")); + } + } + // Custom registration function for extensions of category "route" function registerRoute(extension) { var route = Object.create(extension); @@ -107,7 +122,7 @@ define( // Utility; create a function which converts another function // (which acts on single objects) to one which acts upon arrays. function mapUpon(func) { - return function(array) { + return function (array) { return array.map(func); }; } @@ -121,6 +136,7 @@ define( directives: mapUpon(new CustomRegistrar("directive")), controllers: mapUpon(new CustomRegistrar("controller")), services: mapUpon(new CustomRegistrar("service")), + runs: mapUpon(registerRun), components: registerComponents }; } diff --git a/platform/framework/test/register/CustomRegistrarsSpec.js b/platform/framework/test/register/CustomRegistrarsSpec.js index 106253ca6c..f7b13caa94 100644 --- a/platform/framework/test/register/CustomRegistrarsSpec.js +++ b/platform/framework/test/register/CustomRegistrarsSpec.js @@ -135,6 +135,14 @@ define( expect(customRegistrars.components).toBeTruthy(); customRegistrars.components([]); }); + + it("warns if no implementation is provided for runs", function () { + // Verify precondition + expect(mockLog.warn).not.toHaveBeenCalled(); + customRegistrars.runs([{ something: "that is not a function"}]); + expect(mockLog.warn).toHaveBeenCalledWith(jasmine.any(String)); + expect(mockApp.run).not.toHaveBeenCalled(); + }); }); } ); \ No newline at end of file