Skip to content

Commit 2d0b37f

Browse files
dpaloujleyva
authored andcommitted
[docs] app: Document policy for signals
1 parent 1202283 commit 2d0b37f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

general/development/policies/codingstyle-moodleapp.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,39 @@ export class MyService {
458458

459459
</InvalidExample>
460460

461+
### Angular Signals
462+
463+
All signals in class properties must be defined as readonly properties to avoid overriding the whole signal by mistake. This includes input signals, computed signals, etc.
464+
465+
<ValidExample title="Good">
466+
467+
```ts
468+
export class MyComponent {
469+
470+
protected readonly myInput = input('...');
471+
protected readonly mySignal = signal('...');
472+
protected readonly myComputed = computed(() => ...);
473+
474+
}
475+
```
476+
477+
</ValidExample>
478+
479+
<InvalidExample title="Bad">
480+
481+
```ts
482+
483+
export class MyComponent {
484+
485+
protected myInput = input('...');
486+
protected mySignal = signal('...');
487+
protected myComputed = computed(() => ...);
488+
489+
}
490+
```
491+
492+
</InvalidExample>
493+
461494
## Angular
462495

463496
### Avoid calling methods in templates

0 commit comments

Comments
 (0)