Angular Best Practices: Difference between revisions
Jump to navigation
Jump to search
Created page with "=Getting Setup= ==Naming== Keep with the style guide. E.g. catalog.component.ts which has CatalogComponent inside. ==File Structures== LIFT, *Locate Code Quickly *Identify co..." |
No edit summary |
||
Line 8: | Line 8: | ||
*Flattest structure possible | *Flattest structure possible | ||
*Try to be DRY | *Try to be DRY | ||
=General Coding= | |||
==Single Responsibility== | |||
The single-responsibility principle (SRP) is a computer-programming principle that states that every module, class or function in a computer program should have responsibility over a single part of that program's functionality, which it should encapsulate. All of that module, class or function's services should be narrowly aligned with that responsibility.[1] | |||
==Symbol Naming== | |||
Stick with the naming conventions in the style guide. Generally for angular we use camel case. | |||
==Immutability== | |||
You should try and use this all the time in javaScript and typeScript. E.g. | |||
<syntaxhighlight lang="js"> | |||
this.currentUser.classes.push(classId) | |||
</syntaxhighlight> | |||
Best Practice would be | |||
<syntaxhighlight lang="js"> | |||
this.currentUser = Object.assign( | |||
{}, | |||
this.currentUsers, | |||
{ | |||
classes: this.currentUser.classes.concat([classId]} | |||
}) | |||
</syntaxhighlight> |
Revision as of 11:37, 5 December 2020
Getting Setup
Naming
Keep with the style guide. E.g. catalog.component.ts which has CatalogComponent inside.
File Structures
LIFT,
- Locate Code Quickly
- Identify code at a glance
- Flattest structure possible
- Try to be DRY
General Coding
Single Responsibility
The single-responsibility principle (SRP) is a computer-programming principle that states that every module, class or function in a computer program should have responsibility over a single part of that program's functionality, which it should encapsulate. All of that module, class or function's services should be narrowly aligned with that responsibility.[1]
Symbol Naming
Stick with the naming conventions in the style guide. Generally for angular we use camel case.
Immutability
You should try and use this all the time in javaScript and typeScript. E.g.
this.currentUser.classes.push(classId)
Best Practice would be
this.currentUser = Object.assign(
{},
this.currentUsers,
{
classes: this.currentUser.classes.concat([classId]}
})