MOBILE-4272 workshop: Decouple services
parent
a5cd697012
commit
0d6eb5cb23
|
@ -23,27 +23,35 @@ 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 { AddonWorkshopAssessmentStrategyDelegateService } from './services/assessment-strategy-delegate';
|
||||
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';
|
||||
import { AddonModWorkshopModuleHandler } from './services/handlers/module';
|
||||
import { AddonModWorkshopProvider } from './services/workshop';
|
||||
import { AddonModWorkshopHelperProvider } from './services/workshop-helper';
|
||||
import { AddonModWorkshopOfflineProvider } from './services/workshop-offline';
|
||||
import { AddonModWorkshopSyncProvider } from './services/workshop-sync';
|
||||
import { ADDON_MOD_WORKSHOP_COMPONENT, ADDON_MOD_WORKSHOP_PAGE_NAME } from '@addons/mod/workshop/constants';
|
||||
import { getCronHandlerInstance } from '@addons/mod/workshop/services/handlers/sync-cron';
|
||||
import { getPrefetchHandlerInstance } from '@addons/mod/workshop/services/handlers/prefetch';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const ADDON_MOD_WORKSHOP_SERVICES: Type<unknown>[] = [
|
||||
/**
|
||||
* Get workshop services.
|
||||
*
|
||||
* @returns Workshop services.
|
||||
*/
|
||||
export async function getWorkshopServices(): Promise<Type<unknown>[]> {
|
||||
const { AddonModWorkshopProvider } = await import('@addons/mod/workshop/services/workshop');
|
||||
const { AddonModWorkshopOfflineProvider } = await import('@addons/mod/workshop/services/workshop-offline');
|
||||
const { AddonModWorkshopSyncProvider } = await import('@addons/mod/workshop/services/workshop-sync');
|
||||
const { AddonModWorkshopHelperProvider } = await import('@addons/mod/workshop/services/workshop-helper');
|
||||
const { AddonWorkshopAssessmentStrategyDelegateService } =
|
||||
await import('@addons/mod/workshop/services/assessment-strategy-delegate');
|
||||
|
||||
return [
|
||||
AddonModWorkshopProvider,
|
||||
AddonModWorkshopOfflineProvider,
|
||||
AddonModWorkshopSyncProvider,
|
||||
AddonModWorkshopHelperProvider,
|
||||
AddonWorkshopAssessmentStrategyDelegateService,
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
|
|
|
@ -126,11 +126,8 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck {
|
|||
this.compiling.emit(true);
|
||||
|
||||
try {
|
||||
const factory = await CoreCompile.createAndCompileComponent(
|
||||
this.text,
|
||||
this.getComponentClass(),
|
||||
this.extraImports,
|
||||
);
|
||||
const componentClass = await this.getComponentClass();
|
||||
const factory = await CoreCompile.createAndCompileComponent(this.text, componentClass, this.extraImports);
|
||||
|
||||
// Destroy previous components.
|
||||
this.componentRef?.destroy();
|
||||
|
@ -166,9 +163,10 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck {
|
|||
*
|
||||
* @returns The component class.
|
||||
*/
|
||||
protected getComponentClass(): Type<unknown> {
|
||||
protected async getComponentClass(): Promise<Type<unknown>> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const compileInstance = this;
|
||||
const lazyLibraries = await CoreCompile.getLazyLibraries();
|
||||
|
||||
// Create the component, using the text as the template.
|
||||
return class CoreCompileHtmlFakeComponent implements OnInit, AfterContentInit, AfterViewInit, OnDestroy {
|
||||
|
@ -184,7 +182,10 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck {
|
|||
this['dataArray'] = [];
|
||||
|
||||
// Inject the libraries.
|
||||
CoreCompile.injectLibraries(this, compileInstance.extraProviders);
|
||||
CoreCompile.injectLibraries(this, [
|
||||
...lazyLibraries,
|
||||
...compileInstance.extraProviders,
|
||||
]);
|
||||
|
||||
// Always add these elements, they could be needed on component init (componentObservable).
|
||||
this['ChangeDetectorRef'] = compileInstance.changeDetector;
|
||||
|
|
|
@ -149,7 +149,7 @@ 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 { ADDON_MOD_WORKSHOP_SERVICES } from '@addons/mod/workshop/workshop.module';
|
||||
import { 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';
|
||||
|
@ -317,7 +317,6 @@ export class CoreCompileProvider {
|
|||
...ADDON_MOD_SURVEY_SERVICES,
|
||||
...ADDON_MOD_URL_SERVICES,
|
||||
...ADDON_MOD_WIKI_SERVICES,
|
||||
...ADDON_MOD_WORKSHOP_SERVICES,
|
||||
...ADDON_NOTES_SERVICES,
|
||||
...ADDON_NOTIFICATIONS_SERVICES,
|
||||
...ADDON_PRIVATEFILES_SERVICES,
|
||||
|
@ -388,6 +387,19 @@ export class CoreCompileProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lazy libraries to inject.
|
||||
*
|
||||
* @returns Lazy libraries.
|
||||
*/
|
||||
async getLazyLibraries(): Promise<Type<unknown>[]> {
|
||||
const ADDON_MOD_WORKSHOP_SERVICES = await getWorkshopServices();
|
||||
|
||||
return [
|
||||
...ADDON_MOD_WORKSHOP_SERVICES,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a dynamic component.
|
||||
*
|
||||
|
|
|
@ -268,11 +268,13 @@ export class CoreSitePluginsHelperProvider {
|
|||
}
|
||||
|
||||
// Create a "fake" instance to hold all the libraries.
|
||||
const lazyLibraries = await CoreCompile.getLazyLibraries();
|
||||
const instance = {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
HANDLER_DISABLED: HANDLER_DISABLED,
|
||||
};
|
||||
CoreCompile.injectLibraries(instance);
|
||||
|
||||
CoreCompile.injectLibraries(instance, lazyLibraries);
|
||||
|
||||
// Add some data of the WS call result.
|
||||
const jsData = CoreSitePlugins.createDataForJS(result);
|
||||
|
|
Loading…
Reference in New Issue