@wavemaker/angular-codegen 11.0.0-next.140027 → 11.0.0-next.71017

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +1,55 @@
1
1
  import {
2
2
  Injectable,
3
- NgModuleFactoryLoader,
4
3
  NgModuleRef,
5
4
  Type,
6
5
  Injector,
7
- SystemJsNgModuleLoader,
8
- Inject,
9
- NgModuleFactory
6
+ Compiler,
7
+ NgModuleFactory,
10
8
  } from '@angular/core';
11
9
  import { PartialRefProvider } from '@wm/core';
12
10
  import { ComponentType } from '@wm/runtime/base';
13
-
11
+ import { partialLazyModules, prefabLazyModules, prefabPartialLazyModules } from '../util/lazy-module-routes';
14
12
 
15
13
  type ModuleWithRoot = Type<any> & { rootComponent: Type<any> };
14
+ type Options = {
15
+ prefab: string
16
+ };
16
17
 
17
18
  @Injectable({
18
19
  providedIn: 'root'
19
20
  })
20
21
  export class LazyComponentRefProviderService extends PartialRefProvider {
21
22
  private moduleRef: NgModuleRef<any>;
22
- constructor(
23
- @Inject(NgModuleFactoryLoader) private loader: SystemJsNgModuleLoader,
24
- private injector: Injector
25
- ) {
23
+
24
+ constructor(private injector: Injector, private compiler: Compiler) {
26
25
  super();
27
26
  }
28
- private getModulePath(componentName: string, componentType: ComponentType, options?: any): string {
29
- if (componentName.length > 0) {
30
- if (componentType === ComponentType.PARTIAL && options && options.prefab) {
31
- return `src/app/prefabs/${options.prefab}/partials/${componentName}/${componentName}.module#${componentName
32
- .charAt(0)
33
- .toUpperCase()}${componentName.slice(1)}Module`;
34
- }
35
- if (componentType === ComponentType.PARTIAL) {
36
- return `src/app/partials/${componentName}/${componentName}.module#${componentName
37
- .charAt(0)
38
- .toUpperCase()}${componentName.slice(1)}Module`;
39
- } else if (componentType === ComponentType.PREFAB) {
40
- return `src/app/prefabs/${componentName}/${componentName}.module#${componentName
41
- .charAt(0)
42
- .toUpperCase()}${componentName.slice(1)}Module`;
43
- }
27
+
28
+ private getLazyModule(componentName: string, componentType: ComponentType, options?: Options) {
29
+ if (componentType === ComponentType.PARTIAL && options && options.prefab) {
30
+ return prefabPartialLazyModules[`${options.prefab}_${componentName}`];
31
+ }
32
+ if (componentType === ComponentType.PARTIAL) {
33
+ return partialLazyModules[componentName];
34
+ }
35
+ if (componentType === ComponentType.PREFAB) {
36
+ return prefabLazyModules[componentName];
37
+ }
38
+ }
39
+
40
+ private async getModuleFactory(moduleOrFactory: NgModuleFactory<any> | Type<any>): Promise<NgModuleFactory<any>> {
41
+ if (moduleOrFactory instanceof NgModuleFactory) {
42
+ return moduleOrFactory;
43
+ } else {
44
+ return this.compiler.compileModuleAsync(moduleOrFactory);
44
45
  }
45
- return null;
46
46
  }
47
- public async getComponentFactoryRef(componentName: string, componentType: ComponentType, options?: {}) {
48
- let moduleFactory: NgModuleFactory<any>;
47
+
48
+ public async getComponentFactoryRef(componentName: string, componentType: ComponentType, options?: Options) {
49
49
  try {
50
- moduleFactory = await this.loader.load(
51
- this.getModulePath(componentName, componentType, options)
52
- );
50
+ const moduleOrFactory = await this.getLazyModule(componentName, componentType, options).loadChildren();
51
+ const moduleFactory = await this.getModuleFactory(moduleOrFactory);
52
+
53
53
  this.moduleRef = moduleFactory.create(this.injector);
54
54
  const rootComponent = (moduleFactory.moduleType as ModuleWithRoot)
55
55
  .rootComponent;
@@ -0,0 +1,4 @@
1
+ // These three objects will be initialized in the code generation phase.
2
+ export const prefabLazyModules = {};
3
+ export const partialLazyModules = {};
4
+ export const prefabPartialLazyModules = {};
@@ -15,7 +15,7 @@ if (environment.production) {
15
15
  }
16
16
 
17
17
  document.addEventListener('DOMContentLoaded', () => {
18
- new Promise( resolve => {
18
+ new Promise<Event | void>( resolve => {
19
19
  if (isSpotcues) {
20
20
  initSpotCues().then(resolve);
21
21
  } else if (window['cordova']) {
@@ -19,6 +19,15 @@
19
19
  "dom"
20
20
  ],
21
21
  "paths": {
22
+ "rxjs/observable/throw": [
23
+ "node_modules/rxjs-compat/_esm2015/observable/throw"
24
+ ],
25
+ "rxjs/observable/*": [
26
+ "node_modules/rxjs-compat/_esm2015/observable/*"
27
+ ],
28
+ "rxjs/Observable": [
29
+ "node_modules/rxjs-compat/_esm2015/Observable"
30
+ ],
22
31
  "@wm/build-task": [
23
32
  "node_modules/@wavemaker/app-ng-runtime/build-task/"
24
33
  ],
@@ -19,6 +19,15 @@
19
19
  "dom"
20
20
  ],
21
21
  "paths": {
22
+ "rxjs/observable/throw": [
23
+ "node_modules/rxjs-compat/_esm2015/observable/throw"
24
+ ],
25
+ "rxjs/observable/*": [
26
+ "node_modules/rxjs-compat/_esm2015/observable/*"
27
+ ],
28
+ "rxjs/Observable": [
29
+ "node_modules/rxjs-compat/_esm2015/Observable"
30
+ ],
22
31
  "@wm/build-task": [
23
32
  "node_modules/@wavemaker/app-ng-runtime/build-task/"
24
33
  ],