Skip to content

Commit

Permalink
feat(module-loader): run outside of angular and in requestIdleCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyscarney committed Mar 8, 2017
1 parent 7dfe061 commit c7ad3ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export class IonicModule {
{ provide: APP_INITIALIZER, useFactory: registerModeConfigs, deps: [ Config ], multi: true },
{ provide: APP_INITIALIZER, useFactory: setupProvideEvents, deps: [ Platform, DomController ], multi: true },
{ provide: APP_INITIALIZER, useFactory: setupTapClick, deps: [ Config, Platform, DomController, App, NgZone, GestureController ], multi: true },
{ provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ Config, DeepLinkConfigToken, ModuleLoader ], multi: true },
{ provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ Config, DeepLinkConfigToken, ModuleLoader, NgZone ], multi: true },

// useClass
// { provide: HAMMER_GESTURE_CONFIG, useClass: IonicGestureConfig },
Expand Down
20 changes: 16 additions & 4 deletions src/util/module-loader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ComponentFactoryResolver, Injectable, Injector, NgModuleFactory, OpaqueToken, Type } from '@angular/core';
import { ComponentFactoryResolver, Injectable, Injector, NgModuleFactory, NgZone, OpaqueToken, Type } from '@angular/core';
import { Config } from '../config/config';
import { DeepLinkConfig } from '../navigation/nav-util';
import { NgModuleLoader } from './ng-module-loader';
import { requestIonicCallback } from './util';

export const LAZY_LOADED_TOKEN = new OpaqueToken('LZYCMP');

Expand Down Expand Up @@ -76,9 +77,8 @@ export interface LoadedModule {
/**
* @private
*/
export function setupPreloading(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader) {
return function() {
if (config.getBoolean('preloadModules')) {
export function setupPreloadingImplementation(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader) {
if (config.getBoolean('preloadModules')) {
const linksToLoad = deepLinkConfig.links.filter(link => !!link.loadChildren && link.priority !== 'off');

// Load the high priority modules first
Expand All @@ -100,5 +100,17 @@ export function setupPreloading(config: Config, deepLinkConfig: DeepLinkConfig,
console.error(err.message);
});
}
}

/**
* @private
*/
export function setupPreloading(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader, ngZone: NgZone) {
return function() {
requestIonicCallback(() => {
ngZone.runOutsideAngular(() => {
setupPreloadingImplementation(config, deepLinkConfig, moduleLoader);
});
});
};
}

0 comments on commit c7ad3ce

Please sign in to comment.