Merge pull request #5227 from FinnStutzenstein/projectorLoadChildrenCallback

Use LoadChildrenCallback instead of deprecated NgModuleFactoryLoader
This commit is contained in:
Sean 2020-02-25 10:50:19 +01:00 committed by GitHub
commit 98146a29c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 46 deletions

View File

@ -1,10 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { SLIDE } from '../../slide-token';
import { SharedModule } from 'app/shared/shared.module'; import { SharedModule } from 'app/shared/shared.module';
import { CommonListOfSpeakersSlideModule } from '../common/common-list-of-speakers-slide.module';
import { CommonListOfSpeakersSlideComponent } from '../common/common-list-of-speakers-slide.component'; import { CommonListOfSpeakersSlideComponent } from '../common/common-list-of-speakers-slide.component';
import { CommonListOfSpeakersSlideModule } from '../common/common-list-of-speakers-slide.module';
import { SLIDE } from '../../slide-token';
@NgModule({ @NgModule({
imports: [CommonModule, SharedModule, CommonListOfSpeakersSlideModule], imports: [CommonModule, SharedModule, CommonListOfSpeakersSlideModule],

View File

@ -1,10 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { SLIDE } from '../../slide-token';
import { SharedModule } from 'app/shared/shared.module'; import { SharedModule } from 'app/shared/shared.module';
import { CommonListOfSpeakersSlideModule } from '../common/common-list-of-speakers-slide.module';
import { CommonListOfSpeakersSlideComponent } from '../common/common-list-of-speakers-slide.component'; import { CommonListOfSpeakersSlideComponent } from '../common/common-list-of-speakers-slide.component';
import { CommonListOfSpeakersSlideModule } from '../common/common-list-of-speakers-slide.module';
import { SLIDE } from '../../slide-token';
@NgModule({ @NgModule({
imports: [CommonModule, SharedModule, CommonListOfSpeakersSlideModule], imports: [CommonModule, SharedModule, CommonListOfSpeakersSlideModule],

View File

@ -11,7 +11,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'agenda/item-list', slide: 'agenda/item-list',
path: 'agenda/item-list', path: 'agenda/item-list',
loadChildren: './slides/agenda/item-list/item-list-slide.module#ItemListSlideModule', loadChildren: () => import('./agenda/item-list/item-list-slide.module').then(m => m.ItemListSlideModule),
verboseName: 'Agenda', verboseName: 'Agenda',
elementIdentifiers: ['name'], elementIdentifiers: ['name'],
canBeMappedToModel: false canBeMappedToModel: false
@ -19,7 +19,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'topics/topic', slide: 'topics/topic',
path: 'topics/topic', path: 'topics/topic',
loadChildren: './slides/topics/topic/topic-slide.module#TopicSlideModule', loadChildren: () => import('./topics/topic/topic-slide.module').then(m => m.TopicSlideModule),
verboseName: 'Topic', verboseName: 'Topic',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true
@ -27,7 +27,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'motions/motion', slide: 'motions/motion',
path: 'motions/motion', path: 'motions/motion',
loadChildren: './slides/motions/motion/motion-slide.module#MotionSlideModule', loadChildren: () => import('./motions/motion/motion-slide.module').then(m => m.MotionSlideModule),
verboseName: 'Motion', verboseName: 'Motion',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true
@ -35,7 +35,8 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'motions/motion-block', slide: 'motions/motion-block',
path: 'motions/motion-block', path: 'motions/motion-block',
loadChildren: './slides/motions/motion-block/motion-block-slide.module#MotionBlockSlideModule', loadChildren: () =>
import('./motions/motion-block/motion-block-slide.module').then(m => m.MotionBlockSlideModule),
verboseName: 'Motion block', verboseName: 'Motion block',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true
@ -43,7 +44,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'users/user', slide: 'users/user',
path: 'users/user', path: 'users/user',
loadChildren: './slides/users/user/user-slide.module#UserSlideModule', loadChildren: () => import('./users/user/user-slide.module').then(m => m.UserSlideModule),
verboseName: 'Participant', verboseName: 'Participant',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true
@ -51,7 +52,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'core/clock', slide: 'core/clock',
path: 'core/clock', path: 'core/clock',
loadChildren: './slides/core/clock/clock-slide.module#ClockSlideModule', loadChildren: () => import('./core/clock/clock-slide.module').then(m => m.ClockSlideModule),
verboseName: 'Clock', verboseName: 'Clock',
elementIdentifiers: ['name'], elementIdentifiers: ['name'],
canBeMappedToModel: false canBeMappedToModel: false
@ -59,7 +60,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'core/countdown', slide: 'core/countdown',
path: 'core/countdown', path: 'core/countdown',
loadChildren: './slides/core/countdown/countdown-slide.module#CountdownSlideModule', loadChildren: () => import('./core/countdown/countdown-slide.module').then(m => m.CountdownSlideModule),
verboseName: 'Countdown', verboseName: 'Countdown',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true
@ -67,7 +68,8 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'core/projector-message', slide: 'core/projector-message',
path: 'core/projector-message', path: 'core/projector-message',
loadChildren: './slides/core/projector-message/projector-message-slide.module#ProjectorMessageSlideModule', loadChildren: () =>
import('./core/projector-message/projector-message-slide.module').then(m => m.ProjectorMessageSlideModule),
verboseName: 'Message', verboseName: 'Message',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true
@ -75,8 +77,10 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'agenda/current-list-of-speakers', slide: 'agenda/current-list-of-speakers',
path: 'agenda/current-list-of-speakers', path: 'agenda/current-list-of-speakers',
loadChildren: loadChildren: () =>
'./slides/agenda/current-list-of-speakers/current-list-of-speakers-slide.module#CurrentListOfSpeakersSlideModule', import('./agenda/current-list-of-speakers/current-list-of-speakers-slide.module').then(
m => m.CurrentListOfSpeakersSlideModule
),
verboseName: 'Current list of speakers', verboseName: 'Current list of speakers',
elementIdentifiers: ['name'], elementIdentifiers: ['name'],
canBeMappedToModel: false canBeMappedToModel: false
@ -84,8 +88,10 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'agenda/current-list-of-speakers-overlay', slide: 'agenda/current-list-of-speakers-overlay',
path: 'agenda/current-list-of-speakers-overlay', path: 'agenda/current-list-of-speakers-overlay',
loadChildren: loadChildren: () =>
'./slides/agenda/current-list-of-speakers-overlay/current-list-of-speakers-overlay-slide.module#CurrentListOfSpeakersOverlaySlideModule', import('./agenda/current-list-of-speakers-overlay/current-list-of-speakers-overlay-slide.module').then(
m => m.CurrentListOfSpeakersOverlaySlideModule
),
verboseName: 'Current list of speakers overlay', verboseName: 'Current list of speakers overlay',
elementIdentifiers: ['name'], elementIdentifiers: ['name'],
canBeMappedToModel: false canBeMappedToModel: false
@ -93,8 +99,10 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'agenda/current-speaker-chyron', slide: 'agenda/current-speaker-chyron',
path: 'agenda/current-speaker-chyron', path: 'agenda/current-speaker-chyron',
loadChildren: loadChildren: () =>
'./slides/agenda/current-speaker-chyron/current-speaker-chyron-slide.module#CurrentSpeakerChyronSlideModule', import('./agenda/current-speaker-chyron/current-speaker-chyron-slide.module').then(
m => m.CurrentSpeakerChyronSlideModule
),
verboseName: 'Current speaker chyron', verboseName: 'Current speaker chyron',
elementIdentifiers: ['name'], elementIdentifiers: ['name'],
canBeMappedToModel: false canBeMappedToModel: false
@ -102,7 +110,8 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'agenda/list-of-speakers', slide: 'agenda/list-of-speakers',
path: 'agenda/list-of-speakers', path: 'agenda/list-of-speakers',
loadChildren: './slides/agenda/list-of-speakers/list-of-speakers-slide.module#ListOfSpeakersSlideModule', loadChildren: () =>
import('./agenda/list-of-speakers/list-of-speakers-slide.module').then(m => m.ListOfSpeakersSlideModule),
verboseName: 'List of speakers', verboseName: 'List of speakers',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: false canBeMappedToModel: false
@ -110,7 +119,8 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'assignments/assignment', slide: 'assignments/assignment',
path: 'assignments/assignment', path: 'assignments/assignment',
loadChildren: './slides/assignments/assignment/assignment-slide.module#AssignmentSlideModule', loadChildren: () =>
import('./assignments/assignment/assignment-slide.module').then(m => m.AssignmentSlideModule),
verboseName: 'Election', verboseName: 'Election',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true
@ -118,7 +128,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'assignments/poll', slide: 'assignments/poll',
path: 'assignments/poll', path: 'assignments/poll',
loadChildren: './slides/assignments/poll/poll-slide.module#PollSlideModule', loadChildren: () => import('./assignments/poll/poll-slide.module').then(m => m.PollSlideModule),
verboseName: 'Poll', verboseName: 'Poll',
elementIdentifiers: ['name', 'assignment_id', 'poll_id'], elementIdentifiers: ['name', 'assignment_id', 'poll_id'],
canBeMappedToModel: false canBeMappedToModel: false
@ -126,7 +136,7 @@ export const allSlides: SlideManifest[] = [
{ {
slide: 'mediafiles/mediafile', slide: 'mediafiles/mediafile',
path: 'mediafiles/mediafile', path: 'mediafiles/mediafile',
loadChildren: './slides/mediafiles/mediafile/mediafile-slide.module#MediafileSlideModule', loadChildren: () => import('./mediafiles/mediafile/mediafile-slide.module').then(m => m.MediafileSlideModule),
verboseName: 'File', verboseName: 'File',
elementIdentifiers: ['name', 'id'], elementIdentifiers: ['name', 'id'],
canBeMappedToModel: true canBeMappedToModel: true

View File

@ -1,4 +1,4 @@
import { ComponentFactory, Inject, Injectable, Injector, NgModuleFactoryLoader, Type } from '@angular/core'; import { Compiler, ComponentFactory, Inject, Injectable, Injector, NgModuleFactory, Type } from '@angular/core';
import { allSlidesDynamicConfiguration } from '../all-slide-configurations'; import { allSlidesDynamicConfiguration } from '../all-slide-configurations';
import { IdentifiableProjectorElement, ProjectorElement } from 'app/shared/models/core/projector'; import { IdentifiableProjectorElement, ProjectorElement } from 'app/shared/models/core/projector';
@ -17,7 +17,7 @@ export class SlideManager {
public constructor( public constructor(
@Inject(SLIDE_MANIFESTS) private manifests: SlideManifest[], @Inject(SLIDE_MANIFESTS) private manifests: SlideManifest[],
private loader: NgModuleFactoryLoader, private compiler: Compiler,
private injector: Injector private injector: Injector
) { ) {
this.manifests.forEach(slideManifest => { this.manifests.forEach(slideManifest => {
@ -88,23 +88,29 @@ export class SlideManager {
const manifest = this.getManifest(slideName); const manifest = this.getManifest(slideName);
// Load the module factory. // Load the module factory.
return this.loader.load(manifest.loadChildren).then(ngModuleFactory => { let ngModuleFactory: NgModuleFactory<any>;
// create the module const loadedModule = await manifest.loadChildren();
const moduleRef = ngModuleFactory.create(this.injector); if (loadedModule instanceof NgModuleFactory) {
ngModuleFactory = loadedModule;
} else {
ngModuleFactory = await this.compiler.compileModuleAsync(loadedModule);
}
// Get the slide provided by the SLIDE-injectiontoken. // create the module
let dynamicComponentType: Type<T>; const moduleRef = ngModuleFactory.create(this.injector);
try {
// Read from the moduleRef injector and locate the dynamic component type // Get the slide provided by the SLIDE-injectiontoken.
dynamicComponentType = moduleRef.injector.get(SLIDE); let dynamicComponentType: Type<T>;
} catch (e) { try {
console.log( // Read from the moduleRef injector and locate the dynamic component type
'The module for Slide "' + slideName + '" is not configured right: Make usage of makeSlideModule.' dynamicComponentType = moduleRef.injector.get(SLIDE);
); } catch (e) {
throw e; console.log(
} 'The module for Slide "' + slideName + '" is not configured right: Make usage of makeSlideModule.'
// Resolve this component factory );
return moduleRef.componentFactoryResolver.resolveComponentFactory<T>(dynamicComponentType); throw e;
}); }
// Resolve this component factory
return moduleRef.componentFactoryResolver.resolveComponentFactory(dynamicComponentType);
} }
} }

View File

@ -1,4 +1,5 @@
import { InjectionToken } from '@angular/core'; import { InjectionToken } from '@angular/core';
import { LoadChildrenCallback } from '@angular/router';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -38,7 +39,7 @@ export interface SlideDynamicConfiguration {
*/ */
export interface SlideManifest extends Slide { export interface SlideManifest extends Slide {
path: string; path: string;
loadChildren: string; loadChildren: LoadChildrenCallback;
verboseName: string; verboseName: string;
elementIdentifiers: (keyof IdentifiableProjectorElement)[]; elementIdentifiers: (keyof IdentifiableProjectorElement)[];
canBeMappedToModel: boolean; canBeMappedToModel: boolean;

View File

@ -1,5 +1,5 @@
import { ModuleWithProviders } from '@angular/compiler/src/core'; import { ModuleWithProviders } from '@angular/compiler/src/core';
import { NgModule, NgModuleFactoryLoader, SystemJsNgModuleLoader } from '@angular/core'; import { NgModule } from '@angular/core';
import { ROUTES } from '@angular/router'; import { ROUTES } from '@angular/router';
import { allSlides } from './all-slides'; import { allSlides } from './all-slides';
@ -15,7 +15,7 @@ import { SLIDE_MANIFESTS } from './slide-manifest';
* found and put in sepearte chunks. * found and put in sepearte chunks.
*/ */
@NgModule({ @NgModule({
providers: [SlideManager, { provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader }] providers: [SlideManager]
}) })
export class SlidesModule { export class SlidesModule {
public static forRoot(): ModuleWithProviders { public static forRoot(): ModuleWithProviders {