From f70fca081e961a997d5b8da6a12e678f207c067d Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 14 Jan 2015 16:33:30 -0800 Subject: [PATCH 1/5] [Framework] Add specs for built-in extension for run Add tests for a built-in extension type to framework to allow app.run to be invoked via bundle extensions. This supports stylesheet injection, which should happen on load but isn't triggered from any particular part of the page. WTD-591. --- .../framework/test/register/CustomRegistrarsSpec.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/framework/test/register/CustomRegistrarsSpec.js b/platform/framework/test/register/CustomRegistrarsSpec.js index d70b7d4f2e..106253ca6c 100644 --- a/platform/framework/test/register/CustomRegistrarsSpec.js +++ b/platform/framework/test/register/CustomRegistrarsSpec.js @@ -20,7 +20,8 @@ define( "directive", "service", "constant", - "config" + "config", + "run" ]); mockLog = jasmine.createSpyObj("$log", [ @@ -39,6 +40,7 @@ define( expect(customRegistrars.services).toBeTruthy(); expect(customRegistrars.routes).toBeTruthy(); expect(customRegistrars.constants).toBeTruthy(); + expect(customRegistrars.runs).toBeTruthy(); }); it("invokes built-in functions on the app", function () { @@ -58,6 +60,11 @@ define( expect(mockApp.constant.calls.length).toEqual(0); customRegistrars.constants([{ key: "a", value: "b" }, { key: "b", value: "c" }, { key: "c", value: "d" }]); expect(mockApp.constant.calls.length).toEqual(3); + + expect(mockApp.run.calls.length).toEqual(0); + customRegistrars.runs([jasmine.createSpy("a"), jasmine.createSpy("a"), jasmine.createSpy("a")]); + expect(mockApp.run.calls.length).toEqual(3); + }); it("warns when keys are not defined, then skips", function () { @@ -81,6 +88,8 @@ define( customRegistrars.constants([{ }, { }, { }]); expect(mockApp.constant.calls.length).toEqual(0); expect(mockLog.warn.calls.length).toEqual(9); + + // Notably, keys are not needed for run calls }); it("allows routes to be registered", function () { From 04ee5bbbb589fc6ec183bcff60299df130f06274 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 14 Jan 2015 16:41:14 -0800 Subject: [PATCH 2/5] [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. --- .../framework/src/register/CustomRegistrars.js | 18 +++++++++++++++++- .../test/register/CustomRegistrarsSpec.js | 8 ++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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 From fcab62b4980fb876049c7de92cb38e9325cfd176 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 14 Jan 2015 17:01:52 -0800 Subject: [PATCH 3/5] [Stylesheets] Add style sheet loader Add style sheet loader and move style sheets inclusion out of index.html. WTD-591. --- index.html | 17 ---------- platform/commonUI/general/bundle.json | 24 ++++++++++++++ .../commonUI/general/src/StyleSheetLoader.js | 31 +++++++++++++++++++ 3 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 platform/commonUI/general/src/StyleSheetLoader.js diff --git a/index.html b/index.html index b2ba8bde66..6b460aefc5 100644 --- a/index.html +++ b/index.html @@ -3,23 +3,6 @@ - - - - - - - - -