Skip to content

Commit bdd0c71

Browse files
authored
Merge pull request #45 from crazyserver/app-docs
Update coding guides for 5.1
2 parents 655273b + 8e00ab8 commit bdd0c71

2 files changed

Lines changed: 22 additions & 69 deletions

File tree

general/app/upgrading/plugins-upgrade-guide.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ Depending on which version of the app you're upgrading from, you'll need to go t
1818

1919
Other than the changes outlined in this document, there may be smaller API changes that aren't highlighted here. Make sure to check the [UPGRADE.md](https://github.com/moodlehq/moodleapp/blob/latest/UPGRADE.md) file for an exhaustive list with all the changes.
2020

21+
## 5.0 to 5.1
22+
23+
In this version, the app has undergone a major framework modernization. The most significant change is the upgrade of **Angular from v17 to v20**.
24+
25+
### Angular 20 Upgrade
26+
27+
This is a major jump that aligns the app with the latest web standards and performance improvements. While Angular 20 maintains backward compatibility for many patterns, there is a key area you should review in your site plugins:
28+
29+
**[New Control Flow Syntax](https://v20.angular.dev/guide/templates/control-flow):** Angular 20 stabilizes the modern control flow syntax. We recommend replacing structural directives like `*ngIf`, `*ngFor`, and `[ngSwitch]` with the new `@if`, `@for`, and `@switch` blocks. We strongly recommend migrating to this new syntax as it offers better performance, improved type safety, and is the current standard for Angular development, while the old directives have been deprecated. This new control flow can be used since Moodle app 4.4.
30+
31+
Make sure to test your plugin thoroughly, especially any custom templates that might be affected by in newer Angular versions. Refer to the official Angular upgrade guide for a detailed list of breaking changes between v17 and v20.
32+
33+
**Note for developers:** Please remember to check the [UPGRADE.md](https://github.com/moodlehq/moodleapp/blob/latest/UPGRADE.md) file regularly for any deprecated methods or classes within the Moodle App API to ensure your plugin remains compatible with future releases.
34+
2135
## 4.4 to 4.5
2236

2337
The Ionic version has been upgraded to v8 (from v7), make sure to check the relevant upgrade guides for [v8](https://ionicframework.com/docs/updating/8-0). In particular, the legacy syntax to declare input labels that was deprecated on Ionic7 now has been removed.

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)