From cd66097a8f0413a123d7ceb437460de880756ad7 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 26 Jul 2023 11:56:27 +0900 Subject: [PATCH] MOBILE-4272 workshop: Decouple component modules --- src/addons/mod/workshop/workshop.module.ts | 15 ++++++++++++--- src/core/features/compile/services/compile.ts | 10 +++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/addons/mod/workshop/workshop.module.ts b/src/addons/mod/workshop/workshop.module.ts index 61314f876..930ba2088 100644 --- a/src/addons/mod/workshop/workshop.module.ts +++ b/src/addons/mod/workshop/workshop.module.ts @@ -21,8 +21,7 @@ import { CoreCourseModulePrefetchDelegate } from '@features/course/services/modu import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreCronDelegate } from '@services/cron'; import { CORE_SITE_SCHEMAS } from '@services/sites'; -import { AddonModWorkshopAssessmentStrategyModule } from './assessment/assessment.module'; -import { AddonModWorkshopComponentsModule } from './components/components.module'; +import { AddonModWorkshopAssessmentStrategyModule } from '@addons/mod/workshop/assessment/assessment.module'; import { ADDON_MOD_WORKSHOP_OFFLINE_SITE_SCHEMA } from './services/database/workshop'; import { AddonModWorkshopIndexLinkHandler } from './services/handlers/index-link'; import { AddonModWorkshopListLinkHandler } from './services/handlers/list-link'; @@ -53,6 +52,17 @@ export async function getWorkshopServices(): Promise[]> { ]; } +/** + * Get workshop component modules. + * + * @returns Workshop component modules. + */ +export async function getWorkshopComponentModules(): Promise { + const { AddonModWorkshopComponentsModule } = await import('@addons/mod/workshop/components/components.module'); + + return [AddonModWorkshopComponentsModule]; +} + const routes: Routes = [ { path: ADDON_MOD_WORKSHOP_PAGE_NAME, @@ -63,7 +73,6 @@ const routes: Routes = [ @NgModule({ imports: [ CoreMainMenuTabRoutingModule.forChild(routes), - AddonModWorkshopComponentsModule, AddonModWorkshopAssessmentStrategyModule, ], providers: [ diff --git a/src/core/features/compile/services/compile.ts b/src/core/features/compile/services/compile.ts index 36631c2b8..b9c5ae548 100644 --- a/src/core/features/compile/services/compile.ts +++ b/src/core/features/compile/services/compile.ts @@ -149,14 +149,13 @@ import { ADDON_MOD_SCORM_SERVICES } from '@addons/mod/scorm/scorm.module'; import { ADDON_MOD_SURVEY_SERVICES } from '@addons/mod/survey/survey.module'; import { ADDON_MOD_URL_SERVICES } from '@addons/mod/url/url.module'; import { ADDON_MOD_WIKI_SERVICES } from '@addons/mod/wiki/wiki.module'; -import { getWorkshopServices } from '@addons/mod/workshop/workshop.module'; +import { getWorkshopComponentModules, getWorkshopServices } from '@addons/mod/workshop/workshop.module'; import { ADDON_NOTES_SERVICES } from '@addons/notes/notes.module'; import { ADDON_NOTIFICATIONS_SERVICES } from '@addons/notifications/notifications.module'; import { ADDON_PRIVATEFILES_SERVICES } from '@addons/privatefiles/privatefiles.module'; // Import some addon modules that define components, directives and pipes. Only import the important ones. import { AddonModAssignComponentsModule } from '@addons/mod/assign/components/components.module'; -import { AddonModWorkshopComponentsModule } from '@addons/mod/workshop/components/components.module'; import { CorePromisedValue } from '@classes/promised-value'; import { CorePlatform } from '@services/platform'; @@ -180,7 +179,10 @@ export class CoreCompileProvider { CoreSharedModule, CoreCourseComponentsModule, CoreCoursesComponentsModule, CoreUserComponentsModule, CoreCourseDirectivesModule, CoreQuestionComponentsModule, AddonModAssignComponentsModule, CoreBlockComponentsModule, CoreEditorComponentsModule, CoreSearchComponentsModule, CoreSitePluginsDirectivesModule, - AddonModWorkshopComponentsModule, + ]; + + protected readonly LAZY_IMPORTS = [ + getWorkshopComponentModules, ]; constructor(protected injector: Injector, compilerFactory: JitCompilerFactory) { @@ -205,7 +207,9 @@ export class CoreCompileProvider { // Create the component using the template and the class. const component = Component({ template })(componentClass); + const lazyImports = await Promise.all(this.LAZY_IMPORTS.map(getModules => getModules())); const imports = [ + ...CoreArray.flatten(lazyImports), ...this.IMPORTS, ...extraImports, ];