Merge pull request #4577 from vparomskiy/master
enhance widget extension loading
This commit is contained in:
commit
ed9555101e
@ -134,6 +134,7 @@ export class ResourcesService {
|
|||||||
try {
|
try {
|
||||||
modules = this.extractNgModules(module);
|
modules = this.extractNgModules(module);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
}
|
}
|
||||||
if (modules && modules.length) {
|
if (modules && modules.length) {
|
||||||
import('@angular/compiler').then(
|
import('@angular/compiler').then(
|
||||||
@ -172,22 +173,44 @@ export class ResourcesService {
|
|||||||
(e) => {
|
(e) => {
|
||||||
this.loadedModules[url].error(new Error(`Unable to load module from url: ${url}`));
|
this.loadedModules[url].error(new Error(`Unable to load module from url: ${url}`));
|
||||||
delete this.loadedModules[url];
|
delete this.loadedModules[url];
|
||||||
|
console.error(`Unable to load module from url: ${url}`, e);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return subject.asObservable();
|
return subject.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractNgModules(module: any, modules: Type<any>[] = []): Type<any>[] {
|
private extractNgModules(module: any, modules: Type<any>[] = []): Type<any>[] {
|
||||||
|
try {
|
||||||
|
let potentialModules = [module];
|
||||||
|
let currentScanDepth = 0;
|
||||||
|
|
||||||
|
while(potentialModules.length && currentScanDepth < 10) {
|
||||||
|
let newPotentialModules = [];
|
||||||
|
for (const module of potentialModules) {
|
||||||
if (module && 'ɵmod' in module) {
|
if (module && 'ɵmod' in module) {
|
||||||
modules.push(module);
|
modules.push(module);
|
||||||
} else {
|
} else {
|
||||||
for (const k of Object.keys(module)) {
|
for (const k of Object.keys(module)) {
|
||||||
this.extractNgModules(module[k], modules);
|
if(!this.isPrimitive(module[k])) {
|
||||||
|
newPotentialModules.push(module[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
potentialModules = newPotentialModules;
|
||||||
|
currentScanDepth++;
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.log('Could not load NgModule', e);
|
||||||
|
}
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isPrimitive(test) {
|
||||||
|
return test !== Object(test);
|
||||||
|
}
|
||||||
|
|
||||||
private loadResourceByType(type: 'css' | 'js', url: string): Observable<any> {
|
private loadResourceByType(type: 'css' | 'js', url: string): Observable<any> {
|
||||||
const subject = new ReplaySubject();
|
const subject = new ReplaySubject();
|
||||||
this.loadedResources[url] = subject;
|
this.loadedResources[url] = subject;
|
||||||
|
|||||||
@ -70,6 +70,8 @@ import * as TbCore from '@core/public-api';
|
|||||||
import * as TbShared from '@shared/public-api';
|
import * as TbShared from '@shared/public-api';
|
||||||
import * as TbHomeComponents from '@home/components/public-api';
|
import * as TbHomeComponents from '@home/components/public-api';
|
||||||
import * as _moment from 'moment';
|
import * as _moment from 'moment';
|
||||||
|
import * as DragDropModule from "@angular/cdk/drag-drop";
|
||||||
|
import * as HttpClientModule from "@angular/common/http";
|
||||||
|
|
||||||
declare const SystemJS;
|
declare const SystemJS;
|
||||||
|
|
||||||
@ -77,6 +79,7 @@ export const modulesMap: {[key: string]: any} = {
|
|||||||
'@angular/animations': SystemJS.newModule(AngularAnimations),
|
'@angular/animations': SystemJS.newModule(AngularAnimations),
|
||||||
'@angular/core': SystemJS.newModule(AngularCore),
|
'@angular/core': SystemJS.newModule(AngularCore),
|
||||||
'@angular/common': SystemJS.newModule(AngularCommon),
|
'@angular/common': SystemJS.newModule(AngularCommon),
|
||||||
|
'@angular/common/http': SystemJS.newModule(HttpClientModule),
|
||||||
'@angular/forms': SystemJS.newModule(AngularForms),
|
'@angular/forms': SystemJS.newModule(AngularForms),
|
||||||
'@angular/flex-layout': SystemJS.newModule(AngularFlexLayout),
|
'@angular/flex-layout': SystemJS.newModule(AngularFlexLayout),
|
||||||
'@angular/platform-browser': SystemJS.newModule(AngularPlatformBrowser),
|
'@angular/platform-browser': SystemJS.newModule(AngularPlatformBrowser),
|
||||||
@ -87,6 +90,7 @@ export const modulesMap: {[key: string]: any} = {
|
|||||||
'@angular/cdk/layout': SystemJS.newModule(AngularCdkLayout),
|
'@angular/cdk/layout': SystemJS.newModule(AngularCdkLayout),
|
||||||
'@angular/cdk/overlay': SystemJS.newModule(AngularCdkOverlay),
|
'@angular/cdk/overlay': SystemJS.newModule(AngularCdkOverlay),
|
||||||
'@angular/cdk/portal': SystemJS.newModule(AngularCdkPortal),
|
'@angular/cdk/portal': SystemJS.newModule(AngularCdkPortal),
|
||||||
|
'@angular/cdk/drag-drop': SystemJS.newModule(DragDropModule),
|
||||||
'@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete),
|
'@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete),
|
||||||
'@angular/material/badge': SystemJS.newModule(AngularMaterialBadge),
|
'@angular/material/badge': SystemJS.newModule(AngularMaterialBadge),
|
||||||
'@angular/material/bottom-sheet': SystemJS.newModule(AngularMaterialBottomSheet),
|
'@angular/material/bottom-sheet': SystemJS.newModule(AngularMaterialBottomSheet),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user