1 | import { Injectable, Injector, OpaqueToken } from '@angular/core';
|
2 | import { NgModuleLoader } from './ng-module-loader';
|
3 | import { requestIonicCallback } from './util';
|
4 | export var LAZY_LOADED_TOKEN = new OpaqueToken('LZYCMP');
|
5 |
|
6 |
|
7 |
|
8 | var ModuleLoader = (function () {
|
9 | |
10 |
|
11 |
|
12 |
|
13 | function ModuleLoader(_ngModuleLoader, _injector) {
|
14 | this._ngModuleLoader = _ngModuleLoader;
|
15 | this._injector = _injector;
|
16 | |
17 |
|
18 |
|
19 | this._cfrMap = new Map();
|
20 | this._promiseMap = new Map();
|
21 | }
|
22 | |
23 |
|
24 |
|
25 |
|
26 | ModuleLoader.prototype.load = function (modulePath) {
|
27 | var _this = this;
|
28 | (void 0) ;
|
29 | var splitString = modulePath.split(SPLITTER);
|
30 | var promise = this._promiseMap.get(modulePath);
|
31 | if (!promise) {
|
32 | promise = this._ngModuleLoader.load(splitString[0], splitString[1]);
|
33 | this._promiseMap.set(modulePath, promise);
|
34 | }
|
35 | return promise.then(function (loadedModule) {
|
36 | (void 0) ;
|
37 | var ref = loadedModule.create(_this._injector);
|
38 | var component = ref.injector.get(LAZY_LOADED_TOKEN);
|
39 | _this._cfrMap.set(component, ref.componentFactoryResolver);
|
40 | return {
|
41 | componentFactoryResolver: ref.componentFactoryResolver,
|
42 | component: component
|
43 | };
|
44 | });
|
45 | };
|
46 | |
47 |
|
48 |
|
49 |
|
50 | ModuleLoader.prototype.getComponentFactoryResolver = function (component) {
|
51 | return this._cfrMap.get(component);
|
52 | };
|
53 | return ModuleLoader;
|
54 | }());
|
55 | export { ModuleLoader };
|
56 | ModuleLoader.decorators = [
|
57 | { type: Injectable },
|
58 | ];
|
59 |
|
60 |
|
61 |
|
62 | ModuleLoader.ctorParameters = function () { return [
|
63 | { type: NgModuleLoader, },
|
64 | { type: Injector, },
|
65 | ]; };
|
66 | function ModuleLoader_tsickle_Closure_declarations() {
|
67 |
|
68 | ModuleLoader.decorators;
|
69 | |
70 |
|
71 |
|
72 |
|
73 | ModuleLoader.ctorParameters;
|
74 | |
75 |
|
76 |
|
77 |
|
78 | ModuleLoader.prototype._cfrMap;
|
79 |
|
80 | ModuleLoader.prototype._promiseMap;
|
81 |
|
82 | ModuleLoader.prototype._ngModuleLoader;
|
83 |
|
84 | ModuleLoader.prototype._injector;
|
85 | }
|
86 | var SPLITTER = '#';
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | export function provideModuleLoader(ngModuleLoader, injector) {
|
94 | return new ModuleLoader(ngModuleLoader, injector);
|
95 | }
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | export function setupPreloadingImplementation(config, deepLinkConfig, moduleLoader) {
|
104 | if (!deepLinkConfig || !deepLinkConfig.links || !config.getBoolean('preloadModules')) {
|
105 | return Promise.resolve();
|
106 | }
|
107 | var linksToLoad = deepLinkConfig.links.filter(function (link) { return !!link.loadChildren && link.priority !== 'off'; });
|
108 |
|
109 | var highPriorityPromises = linksToLoad
|
110 | .filter(function (link) { return link.priority === 'high'; })
|
111 | .map(function (link) { return moduleLoader.load(link.loadChildren); });
|
112 | return Promise.all(highPriorityPromises).then(function () {
|
113 |
|
114 | var lowPriorityPromises = linksToLoad
|
115 | .filter(function (link) { return link.priority === 'low'; })
|
116 | .map(function (link) { return moduleLoader.load(link.loadChildren); });
|
117 | return Promise.all(lowPriorityPromises);
|
118 | }).catch(function (err) {
|
119 | console.error(err.message);
|
120 | });
|
121 | }
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | export function setupPreloading(config, deepLinkConfig, moduleLoader, ngZone) {
|
131 | return function () {
|
132 | requestIonicCallback(function () {
|
133 | ngZone.runOutsideAngular(function () {
|
134 | setupPreloadingImplementation(config, deepLinkConfig, moduleLoader);
|
135 | });
|
136 | });
|
137 | };
|
138 | }
|
139 |
|
\ | No newline at end of file |