From 2afc5cfeda96a822f0dce5c7aa289002ebae8bd1 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Mon, 1 May 2017 02:25:45 +0200 Subject: [PATCH] fix(module-loader): null references --- src/util/module-loader.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/util/module-loader.ts b/src/util/module-loader.ts index 7d5b2dd3c9f..fcd918cde48 100644 --- a/src/util/module-loader.ts +++ b/src/util/module-loader.ts @@ -75,24 +75,26 @@ export interface LoadedModule { * @hidden */ export function setupPreloadingImplementation(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader): Promise { - if (config.getBoolean('preloadModules') && deepLinkConfig && deepLinkConfig.links) { - const linksToLoad = deepLinkConfig.links.filter(link => !!link.loadChildren && link.priority !== 'off'); + if (!deepLinkConfig || !deepLinkConfig.links || !config.getBoolean('preloadModules')) { + return Promise.resolve(); + } + const linksToLoad = deepLinkConfig.links.filter(link => !!link.loadChildren && link.priority !== 'off'); + + // Load the high priority modules first + const highPriorityPromises = linksToLoad + .filter(link => link.priority === 'high') + .map(link => moduleLoader.load(link.loadChildren)); - // Load the high priority modules first - const highPriorityPromises = linksToLoad.filter(link => link.priority === 'high') + return Promise.all(highPriorityPromises).then(() => { + // Load the low priority modules after the high priority are done + const lowPriorityPromises = linksToLoad + .filter(link => link.priority === 'low') .map(link => moduleLoader.load(link.loadChildren)); - return Promise.all(highPriorityPromises).then(() => { - // Load the low priority modules after the high priority are done - const lowPriorityPromises = linksToLoad.filter(link => link.priority === 'low') - .map(link => moduleLoader.load(link.loadChildren)); - return Promise.all(lowPriorityPromises); - }).catch(err => { - console.error(err.message); - }); - } else { - return Promise.resolve(); - } + return Promise.all(lowPriorityPromises); + }).catch(err => { + console.error(err.message); + }); } /**