a zip code crypto-currency system good for red ONLY

module-loader.js 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { Injectable, InjectionToken, Injector } from '@angular/core';
  2. import { NgModuleLoader } from './ng-module-loader';
  3. import { requestIonicCallback } from './util';
  4. export const LAZY_LOADED_TOKEN = new InjectionToken('LZYCMP');
  5. /**
  6. * @hidden
  7. */
  8. export class ModuleLoader {
  9. constructor(_ngModuleLoader, _injector) {
  10. this._ngModuleLoader = _ngModuleLoader;
  11. this._injector = _injector;
  12. /** @internal */
  13. this._cfrMap = new Map();
  14. this._promiseMap = new Map();
  15. }
  16. load(modulePath) {
  17. (void 0) /* console.time */;
  18. const splitString = modulePath.split(SPLITTER);
  19. let promise = this._promiseMap.get(modulePath);
  20. if (!promise) {
  21. promise = this._ngModuleLoader.load(splitString[0], splitString[1]);
  22. this._promiseMap.set(modulePath, promise);
  23. }
  24. return promise.then(loadedModule => {
  25. (void 0) /* console.timeEnd */;
  26. const ref = loadedModule.create(this._injector);
  27. const component = ref.injector.get(LAZY_LOADED_TOKEN);
  28. this._cfrMap.set(component, ref.componentFactoryResolver);
  29. return {
  30. componentFactoryResolver: ref.componentFactoryResolver,
  31. component: component
  32. };
  33. });
  34. }
  35. getComponentFactoryResolver(component) {
  36. return this._cfrMap.get(component);
  37. }
  38. }
  39. ModuleLoader.decorators = [
  40. { type: Injectable },
  41. ];
  42. /** @nocollapse */
  43. ModuleLoader.ctorParameters = () => [
  44. { type: NgModuleLoader, },
  45. { type: Injector, },
  46. ];
  47. const SPLITTER = '#';
  48. /**
  49. * @hidden
  50. */
  51. export function provideModuleLoader(ngModuleLoader, injector) {
  52. return new ModuleLoader(ngModuleLoader, injector);
  53. }
  54. /**
  55. * @hidden
  56. */
  57. export function setupPreloadingImplementation(config, deepLinkConfig, moduleLoader) {
  58. if (!deepLinkConfig || !deepLinkConfig.links || !config.getBoolean('preloadModules')) {
  59. return Promise.resolve();
  60. }
  61. const linksToLoad = deepLinkConfig.links.filter(link => !!link.loadChildren && link.priority !== 'off');
  62. // Load the high priority modules first
  63. const highPriorityPromises = linksToLoad
  64. .filter(link => link.priority === 'high')
  65. .map(link => moduleLoader.load(link.loadChildren));
  66. return Promise.all(highPriorityPromises).then(() => {
  67. // Load the low priority modules after the high priority are done
  68. const lowPriorityPromises = linksToLoad
  69. .filter(link => link.priority === 'low')
  70. .map(link => moduleLoader.load(link.loadChildren));
  71. return Promise.all(lowPriorityPromises);
  72. }).catch(err => {
  73. console.error(err.message);
  74. });
  75. }
  76. /**
  77. * @hidden
  78. */
  79. export function setupPreloading(config, deepLinkConfig, moduleLoader, ngZone) {
  80. return function () {
  81. requestIonicCallback(() => {
  82. ngZone.runOutsideAngular(() => {
  83. setupPreloadingImplementation(config, deepLinkConfig, moduleLoader);
  84. });
  85. });
  86. };
  87. }
  88. //# sourceMappingURL=module-loader.js.map