From 49de372056b1e5af054933af65accd2e548b29b0 Mon Sep 17 00:00:00 2001 From: Russ Watson Date: Tue, 4 Oct 2016 10:33:52 -0500 Subject: [PATCH 1/4] Updates the navigation strategy to handle and expect a resolved string or object of viewport names with module ids for each key. --- src/router.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/router.js b/src/router.js index b7bd3f38..5a92037a 100644 --- a/src/router.js +++ b/src/router.js @@ -452,13 +452,18 @@ function validateRouteConfig(config: RouteConfig, routes: Array): void { } function evaluateNavigationStrategy(instruction: NavigationInstruction, evaluator: Function, context: any): Promise { - return Promise.resolve(evaluator.call(context, instruction)).then(() => { + return Promise.resolve(evaluator.call(context, instruction)).then((modules: string | {[viewportname: string]: moduleId}) => { if (!('viewPorts' in instruction.config)) { - instruction.config.viewPorts = { - 'default': { - moduleId: instruction.config.moduleId - } - }; + instruction.config.viewPorts = {}; + } + + if (typeof modules === 'string') { + modules = {'default': modules}; + } + + for (let key in modules) { + let vp = instruction.config.viewPorts[key] || {}; + vp.moduleId = modules[key]; } return instruction; From 235c165e93ec4bc9d0d043e954f378d85f9ff88a Mon Sep 17 00:00:00 2001 From: Russ Watson Date: Tue, 4 Oct 2016 10:33:59 -0500 Subject: [PATCH 2/4] Making the evaluated function backwards compatible for existing callbacks on the navigation strategy --- src/router.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/router.js b/src/router.js index 5a92037a..2443eaca 100644 --- a/src/router.js +++ b/src/router.js @@ -459,6 +459,8 @@ function evaluateNavigationStrategy(instruction: NavigationInstruction, evaluato if (typeof modules === 'string') { modules = {'default': modules}; + } else if (modules === undefined) { + modules = {'default': instruction.config.moduleId}; } for (let key in modules) { From e6accee03d4e9a9190ca1fa4bf642a1728147478 Mon Sep 17 00:00:00 2001 From: Russ Watson Date: Tue, 4 Oct 2016 10:34:03 -0500 Subject: [PATCH 3/4] Annotates the modules parameter as optional now that it is backwards compatible --- src/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router.js b/src/router.js index 2443eaca..db2c673d 100644 --- a/src/router.js +++ b/src/router.js @@ -452,7 +452,7 @@ function validateRouteConfig(config: RouteConfig, routes: Array): void { } function evaluateNavigationStrategy(instruction: NavigationInstruction, evaluator: Function, context: any): Promise { - return Promise.resolve(evaluator.call(context, instruction)).then((modules: string | {[viewportname: string]: moduleId}) => { + return Promise.resolve(evaluator.call(context, instruction)).then((modules?: string | {[viewportname: string]: moduleId}) => { if (!('viewPorts' in instruction.config)) { instruction.config.viewPorts = {}; } From 377fd8bf9d1019f1596cb9db4ff426198766c785 Mon Sep 17 00:00:00 2001 From: Russ Watson Date: Tue, 4 Oct 2016 10:34:06 -0500 Subject: [PATCH 4/4] Sets the viewport object for the specified key on the instruction's config object --- src/router.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/router.js b/src/router.js index db2c673d..24ce0a70 100644 --- a/src/router.js +++ b/src/router.js @@ -466,6 +466,7 @@ function evaluateNavigationStrategy(instruction: NavigationInstruction, evaluato for (let key in modules) { let vp = instruction.config.viewPorts[key] || {}; vp.moduleId = modules[key]; + instruction.config.viewPorts[key] = vp; } return instruction;