Skip to content

Commit

Permalink
fix(module-loader): null references
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed May 1, 2017
1 parent 45e71a6 commit 2afc5cf
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/util/module-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,26 @@ export interface LoadedModule {
* @hidden
*/
export function setupPreloadingImplementation(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader): Promise<any> {
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);
});
}

/**
Expand Down

0 comments on commit 2afc5cf

Please sign in to comment.