[Framework] Implement runs category-of-extension

Implement 'runs' as a built-in category of extension, to support
bundle addition of functions to run when the application first
starts. Specifically supports loading of stylesheets, WTD-591.
This commit is contained in:
Victor Woeltjen 2015-01-14 16:41:14 -08:00
parent f70fca081e
commit 04ee5bbbb5
2 changed files with 25 additions and 1 deletions

View File

@ -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);
@ -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
};
}

View File

@ -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();
});
});
}
);