Skip to content

Commit 8e00ab8

Browse files
committed
[docs] app: Update coding style for 5.1
1 parent f18eb96 commit 8e00ab8

1 file changed

Lines changed: 8 additions & 69 deletions

File tree

general/development/policies/codingstyle-moodleapp.md

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -601,37 +601,9 @@ There is a maximum line length of 140 characters for templates. Whenever that le
601601
If you are using VSCode, this should be done automatically on every save with the [configuration that ships with the app](https://github.com/moodlehq/moodleapp/blob/latest/.vscode/settings.json#L8).
602602
:::
603603

604-
### Avoid default exports
605-
606-
Using default exports should be avoided for Angular applications because they [cause issues with AOT compiler](https://stackoverflow.com/questions/45962317/why-isnt-export-default-recommended-in-angular). Technically only components have this problem, but in order to avoid the mental load of thinking about this every time, we disallow it altogether.
607-
608-
<ValidExample title="Good">
609-
610-
```ts
611-
@Component({
612-
selector: 'my-component',
613-
templateUrl: 'my-component.html',
614-
})
615-
export class MyComponent {}
616-
```
617-
618-
</ValidExample>
619-
620-
<InvalidExample title="Bad">
621-
622-
```ts
623-
@Component({
624-
selector: 'my-component',
625-
templateUrl: 'my-component.html',
626-
})
627-
export default class MyComponent {}
628-
```
629-
630-
</InvalidExample>
631-
632604
### Declaring page modules
633605

634-
When creating a page component, it should be declared in the feature's [lazy modules](../../../general/app/development/development-guide.md#routing). Exceptionally, pages that are used by more than one module can create a page module; but this module should only declare components, it shouldn't include any routing functionality.
606+
When creating a page component, it should be declared as a standalone component and exported as default class so it can be easily [lazy loaded](../../../general/app/development/development-guide.md#routing).
635607

636608
<ValidExample title="Good">
637609

@@ -640,66 +612,33 @@ When creating a page component, it should be declared in the feature's [lazy mod
640612
@Component({
641613
selector: 'page-core-feature-index',
642614
templateUrl: 'index.html',
615+
imports: [
616+
CoreSharedModule,
617+
],
643618
})
644-
export class CoreFeatureIndexPageComponent {}
619+
export default class CoreFeatureIndexPageComponent {}
645620
```
646621

647622
```ts
648-
// file: core/features/feature/feature-lazy.module.ts
623+
// file: core/features/feature/feature.module.ts
649624
const routes: Routes = [
650625
{
651626
path: 'feature',
652-
component: CoreFeatureIndexPageComponent,
627+
loadComponent: () => import('./pages/index/index'),
653628
},
654629
];
655-
656-
@NgModule({
657-
imports: [
658-
RouterModule.forChild(routes),
659-
CoreSharedModule,
660-
],
661-
declarations: [
662-
CoreFeatureIndexPageComponent,
663-
],
664-
})
665-
export class CoreFeatureLazyModule {}
666630
```
667631

668632
</ValidExample>
669633

670-
<CodeExample type="warning" title="Allowed only if the page is used in multiple modules">
671-
672-
```ts
673-
// file: core/features/feature/pages/index/index.page.ts
674-
@Component({
675-
selector: 'page-core-feature-index',
676-
templateUrl: 'index.html',
677-
})
678-
export class CoreFeatureIndexPageComponent {}
679-
```
680-
681-
```ts
682-
// file: core/features/feature/pages/index/index.module.ts
683-
@NgModule({
684-
imports: [
685-
CoreSharedModule,
686-
],
687-
declarations: [
688-
CoreFeatureIndexPageComponent,
689-
],
690-
})
691-
export class CoreFeatureIndexPageModule {}
692-
```
693-
694-
</CodeExample>
695-
696634
<InvalidExample title="Bad">
697635

698636
```ts
699637
// file: core/features/feature/pages/index/index.page.ts
700638
@Component({
701639
selector: 'page-core-feature-index',
702640
templateUrl: 'index.html',
641+
standalone: false,
703642
})
704643
export class CoreFeatureIndexPageComponent {}
705644
```

0 commit comments

Comments
 (0)