You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Copy file name to clipboardExpand all lines: public/docs/ts/latest/guide/style-guide.jade
+50-49
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,8 @@ include ../_util-fns
37
37
:marked
38
38
## File Structure Conventions
39
39
40
-
Some code examples display a file that has one or more similarly named companion files. (e.g. hero.component.ts and hero.component.html).
40
+
Some code examples display a file that has one or more similarly named companion files.
41
+
For example, `hero.component.ts` and `hero.component.html`.
41
42
42
43
The guideline will use the shortcut `hero.component.ts|html|css|spec` to represent those various files. Using this shortcut makes this guide's file structures easier to read and more terse.
1. [App Structure and Angular Modules](#app-structure-and-angular-modules)
53
+
1. [Coding conventions](#coding-conventions)
54
+
1. [App structure and Angular modules](#app-structure-and-angular-modules)
54
55
1. [Components](#components)
55
56
1. [Directives](#directives)
56
57
1. [Services](#services)
57
-
1. [Data Services](#data-services)
58
-
1. [Lifecycle Hooks](#lifecycle-hooks)
58
+
1. [Data services](#data-services)
59
+
1. [Lifecycle hooks](#lifecycle-hooks)
59
60
1. [Appendix](#appendix)
60
61
61
62
.l-main-section
62
63
:marked
63
64
## Single Responsibility
64
65
65
-
Apply the [Single Responsibility Principle](https://wikipedia.org/wiki/Single_responsibility_principle) to all components, services, and other symbols.
66
+
Apply the [single responsibility principle](https://wikipedia.org/wiki/Single_responsibility_principle) to all components, services, and other symbols.
66
67
This helps make the app cleaner, easier to read and maintain, and more testable.
67
68
68
69
### <a id="01-01"></a>Rule of One
69
70
#### <a href="#01-01">Style 01-01</a>
70
71
.s-rule.do
71
72
:marked
72
-
**Do** define one thing (e.g. service or component) per file.
73
+
**Do** define one thing, such as a service or component, per file.
73
74
74
75
.s-rule.consider
75
76
:marked
@@ -85,15 +86,16 @@ a(id='toc')
85
86
86
87
.s-why.s-why-last
87
88
:marked
88
-
**Why?** A single component can be the default export for its file which facilitates lazy loading with the Router.
89
+
**Why?** A single component can be the default export for its file which facilitates lazy loading with the router.
89
90
:marked
90
91
The key is to make the code more reusable, easier to read, and less mistake prone.
91
92
92
93
The following *negative* example defines the `AppComponent`, bootstraps the app, defines the `Hero` model object, and loads heroes from the server ... all in the same file. *Don't do this*.
that humans start to struggle when the number of adjacent interesting things exceeds nine.
@@ -1099,7 +1093,7 @@ a(href="#toc") Back to top
1099
1093
1100
1094
.s-rule.consider
1101
1095
:marked
1102
-
**Consider** creating a folder for a component when is has multiple accompanying files (`.ts`, `.html`, `.css` and `.spec`).
1096
+
**Consider** creating a folder for a component when it has multiple accompanying files (`.ts`, `.html`, `.css` and `.spec`).
1103
1097
1104
1098
.s-why
1105
1099
:marked
@@ -1169,7 +1163,7 @@ a(id='file-tree')
1169
1163
1170
1164
.l-sub-section
1171
1165
:marked
1172
-
While components in dedicated folder are widely preferred,
1166
+
While components in dedicated folders are widely preferred,
1173
1167
another option for small apps is to keep components flat (not in a dedicated folder).
1174
1168
This adds up to four files to the existing folder, but also reduces the folder nesting.
1175
1169
Whatever you choose, be consistent.
@@ -1187,7 +1181,8 @@ a(href="#toc") Back to top
1187
1181
1188
1182
.s-why
1189
1183
:marked
1190
-
**Why?** A developer can locate the code, identify what each file represents at a glance, the structure is as flat as it can be, and there is no repetitive nor redundant names.
1184
+
**Why?** A developer can locate the code, identify what each file represents
1185
+
at a glance, the structure is as flat as it can be, and there are no repetitive nor redundant names.
1191
1186
1192
1187
.s-why
1193
1188
:marked
@@ -1214,7 +1209,7 @@ a(href="#toc") Back to top
1214
1209
**Why?** Angular modules make it easier to isolate, test, and re-use features.
1215
1210
1216
1211
.file-tree-reference
1217
-
a(href="#file-tree") Refer here to this Folder and File Structure example
1212
+
a(href="#file-tree") Refer to this Folder and File Structure example
1218
1213
1219
1214
a(href="#toc") Back to top
1220
1215
:marked
@@ -1303,7 +1298,7 @@ a(href="#toc") Back to top
1303
1298
1304
1299
.s-rule.do
1305
1300
:marked
1306
-
**Do** put common components, directives and pipes that will be used throughout the application by other feature modules in the `SharedModule`, where those assets are expected to share a new instance of themselves (not singletons).
1301
+
**Do** put common components, directives, and pipes that will be used throughout the application by other feature modules in the `SharedModule`, where those assets are expected to share a new instance of themselves (not singletons).
1307
1302
1308
1303
.s-rule.do
1309
1304
:marked
@@ -1384,7 +1379,7 @@ a(href="#toc") Back to top
1384
1379
1385
1380
.s-rule.do
1386
1381
:marked
1387
-
**Do** collect single-use classes and hiding their gory details inside `CoreModule`. A simplified root `AppModule` imports `CoreModule` in its capacity as orchestrator of the application as a whole.
1382
+
**Do** collect single-use classes and hide their gory details inside `CoreModule`. A simplified root `AppModule` imports `CoreModule` in its capacity as orchestrator of the application as a whole.
1388
1383
1389
1384
.s-rule.do
1390
1385
:marked
@@ -1431,7 +1426,7 @@ a(href="#toc") Back to top
1431
1426
1432
1427
.s-rule.do
1433
1428
:marked
1434
-
**Do** export all symbols that from the `CoreModule` that the `AppModule` will import and make available for other feature modules to use.
1429
+
**Do** export all symbols from the `CoreModule` that the `AppModule` will import and make available for other feature modules to use.
1435
1430
1436
1431
.s-why
1437
1432
:marked
@@ -1692,7 +1687,7 @@ a(href="#toc") Back to top
1692
1687
.s-why
1693
1688
:marked
1694
1689
**Why?** If you ever need to rename the property or event name associated with
1695
-
`@Input` or `@Output`, you can modify it a single place.
1690
+
`@Input` or `@Output`, you can modify it in a single place.
1696
1691
1697
1692
.s-why
1698
1693
:marked
@@ -1721,7 +1716,8 @@ a(href="#toc") Back to top
1721
1716
1722
1717
.s-why.s-why-last
1723
1718
:marked
1724
-
**Why?** May lead to confusion when the output or the input properties of a given directive are named a given way but exported differently as a public API.
1719
+
**Why?** May lead to confusion when the output or the input
1720
+
properties of a given directive are named one way but exported differently as a public API.
**Why?** The Angular DI mechanism resolves all dependencies of services based on their types declared with the services' constructors.
2021
+
**Why?** The Angular Dependency Injection (DI) mechanism resolves all dependencies
2022
+
of services based on their types declared with the services' constructors.
2026
2023
2027
2024
.s-why.s-why-last
2028
2025
:marked
@@ -2061,7 +2058,11 @@ a(href="#toc") Back to top
2061
2058
2062
2059
.s-why.s-why-last
2063
2060
:marked
2064
-
**Why?** Data service implementation may have very specific code to handle the data repository. This may include headers, how to talk to the data, or other services such as `Http`. Separating the logic into a data service encapsulates this logic in a single place hiding the implementation from the outside consumers (perhaps a component), also making it easier to change the implementation.
2061
+
**Why?** Data service implementation may have very specific code to handle the data repository.
2062
+
This may include headers, how to talk to the data, or other services such as `Http`.
2063
+
Separating the logic into a data service encapsulates this logic in a
2064
+
single place and hides the implementation from the outside consumers
2065
+
(perhaps a component). This also makes it easier to change the implementation.
2065
2066
2066
2067
a(href="#toc") Back to top
2067
2068
@@ -2084,7 +2085,7 @@ a(href="#toc") Back to top
2084
2085
2085
2086
.s-why.s-why-last
2086
2087
:marked
2087
-
**Why?** Strongly-typed method signatures.
2088
+
**Why?** Lifecycle hook interfaces use strongly-typed method signatures.
2088
2089
The compiler and editor can call out misspellings.
0 commit comments