XpertSolvers: Your Partner in Building Innovative Software Solutions
Building maintainable web apps with Angular MS TechDays 2017
1.
2.
3.
4.
5.
6.
7.
8. “The ratio of time spent reading versus
writing is well over 10 to 1.
We are constantly reading old code as part
of the effort to write new code”
9.
10.
11. Boy Scouts have a rule regarding
camping, that they should leave the
campground cleaner than
they found it. ... By ensuring that the
campground is cleaner when they
leave than it was when
they arrived.
12. Readability is king!
Use consistent naming through chain
(DB -> WebApi -> Angular)
Ubiquitious language (DDD) | Vocabulary
Naming guidance:
https://angular.io/guide/styleguide
13. Symbol name with suffix (.component.ts, .service.ts)
Functional naming (NavigationComponent,
LoggerService)
Do use PascalCasing when naming classes, interfaces
Do use camelCasing to name properties and methods
14. One Component per file
Do make locating code intuitive, simple and fast
Do create folders named for the feature area they
represent
Do extract templates and styles into a separate file,
when more than 3 lines
17. A class should have just a single responsibility
Design for low coupling and high cohesion
18. Apply the single responsibility principle to all
components, services, and other classes
The number of functions on a class should be very
limited
The number of lines of each function should be
very limited
19.
20. Child 2
@OUTPUT
A component can send data to its parent by triggering an event the parent listens to
@INPUT
A component can receive data from its parent
Parent
Child 1
@OUTPUT
@INPUT
24. A class receives its dependencies from external
sources rather than creating them itself.
Create a loosely coupled system
Angular ships with its own dependency injection
framework
25. import { Injectable } from '@angular/core';
import { IFilter } from '../interfaces/IFilter';
@Injectable()
export class SessionstorageService {
public loadFilter(): IFilter {
. . .
return filter;
}
public saveFilter(filter: IFilter): void {
. . .
}
}
@Component()
export class FilterComponent {
constructor(private sessionStorageService: SessionStorageService)
}
28. Support for multiple environments:
(Test, Acceptance, Production)
Supporting hotfixes and parallel development
Feature branches
29.
30.
31. Guards against changes that break existing code
(“regressions”).
Clarifies what the code does, it is a specification.
Reveals mistakes in design and implementation.
32. Isolated unit tests for pipes and services
Angular testing utillities for Components
Karma/Jasmine integration
https://angular.io/guide/testing