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
+62-27
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ a(id='toc')
63
63
:marked
64
64
## Single Responsibility
65
65
66
-
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 (SPR)](https://wikipedia.org/wiki/Single_responsibility_principle) to all components, services, and other symbols.
67
67
This helps make the app cleaner, easier to read and maintain, and more testable.
Redistributing the component and supporting activities into their own dedicated files
99
-
is a better practice.
98
+
It is a better practice to redistribute the component and its
99
+
supporting classes into their own, dedicated files.
100
100
101
101
+makeTabs(
102
102
`style-guide/ts/01-01/main.ts,
@@ -239,20 +239,25 @@ a(href="#toc") Back to top
239
239
240
240
.s-rule.do
241
241
:marked
242
-
**Do** match the name of the symbol to the name of the file.
242
+
**Do** use upper camel case for class names.
243
243
244
244
.s-rule.do
245
245
:marked
246
-
**Do** append the symbol name with the conventional suffix for a thing of that type.
247
-
For example, `Component`, `Directive`, `Module`, `Pipe`, `Service`.
246
+
**Do** match the name of the symbol to the name of the file.
248
247
249
248
.s-rule.do
250
249
:marked
251
-
**Do** give the filename the conventional suffix for a file of that type.
252
-
For example, `.component.ts`, `.directive.ts`, `.module.ts`, `.pipe.ts`, `.service.ts`.
250
+
**Do** append the symbol name with the conventional suffix (such as `Component`,
251
+
`Directive`, `Module`, `Pipe`, or `Service`) for a thing of that type.
252
+
253
+
.s-rule.do
254
+
:marked
255
+
**Do** give the filename the conventional suffix (such as `.component.ts`, `.directive.ts`,
256
+
`.module.ts`, `.pipe.ts`, or `.service.ts`) for a file of that type.
253
257
.s-why
254
258
:marked
255
-
**Why?** Provides a conventional and consistent way to quickly identify and reference assets.
259
+
**Why?** Consistent conventions make it easy to quickly identify
260
+
and reference assets of different types.
256
261
257
262
- var top="vertical-align:top"
258
263
table(width="100%")
@@ -340,7 +345,15 @@ a(href="#toc") Back to top
340
345
341
346
.s-rule.do
342
347
:marked
343
-
**Do** suffix services with `Service` when it is not clear what they are, such as when they are nouns.
348
+
**Do** suffix a service class name with Service.
349
+
For example, something that gets data or heroes
350
+
should be called a `DataService` or a `HeroService`.
351
+
352
+
A few terms are unambiguously services. They typically
353
+
indicate agency by ending in "er". You may prefer to name
354
+
a service that logs messages `Logger` rather than `LoggerService`.
355
+
Decide if this exception is agreeable in your project.
356
+
As always, strive for consistency.
344
357
345
358
.s-why
346
359
:marked
@@ -1106,7 +1119,7 @@ a(href="#toc") Back to top
1106
1119
1107
1120
a(id='file-tree')
1108
1121
:marked
1109
-
Here is a compliant folder and file structure
1122
+
Here is a compliant folder and file structure:
1110
1123
1111
1124
.filetree
1112
1125
.file<project root>
@@ -1183,7 +1196,7 @@ a(href="#toc") Back to top
1183
1196
.s-why
1184
1197
:marked
1185
1198
**Why?** A developer can locate the code, identify what each file represents
1186
-
at a glance, the structure is as flat as it can be, and there are no repetitive nor redundant names.
1199
+
at a glance, the structure is as flat as it can be, and there are no repetitive or redundant names.
1187
1200
1188
1201
.s-why
1189
1202
:marked
@@ -1210,7 +1223,7 @@ a(href="#toc") Back to top
1210
1223
**Why?** Angular modules make it easier to isolate, test, and re-use features.
1211
1224
1212
1225
.file-tree-reference
1213
-
a(href="#file-tree") Refer to this Folder and File Structure example
1226
+
a(href="#file-tree") Refer to this _folder and file structure_ example.
1214
1227
1215
1228
a(href="#toc") Back to top
1216
1229
:marked
@@ -1299,7 +1312,19 @@ a(href="#toc") Back to top
1299
1312
1300
1313
.s-rule.do
1301
1314
:marked
1302
-
**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).
1315
+
**Do** declare components, directives, and pipes in a shared module when those
1316
+
items will be re-used and referenced by the components declared in other feature modules.
1317
+
1318
+
.s-rule.consider
1319
+
:marked
1320
+
**Consider** using the name SharedModule, when the contents of a shared
1321
+
module are referenced across the entire application.
1322
+
1323
+
.s-rule.do
1324
+
:marked
1325
+
**Do** not provide services in shared modules. Services are usually
1326
+
singletons that are provided once for the entire application or
1327
+
in a particular feature module.
1303
1328
1304
1329
.s-rule.do
1305
1330
:marked
@@ -1378,9 +1403,16 @@ a(href="#toc") Back to top
1378
1403
### <a id="04-11"></a>Core Feature Module
1379
1404
#### <a href="#04-11">Style 04-11</a>
1380
1405
1381
-
.s-rule.do
1406
+
.s-rule.consider
1382
1407
:marked
1383
-
**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.
1408
+
**Consider** collecting numerous, auxiliary, single-use classes inside a core module
1409
+
to simplify the apparent structure of a feature module.
1410
+
1411
+
.s-rule.consider
1412
+
:marked
1413
+
**Consider** calling the application-wide core module, `CoreModule`.
1414
+
Importing `CoreModule` into the root `AppModule` reduces its complexity
1415
+
and emphasizes its role as orchestrator of the application as a whole.
1384
1416
1385
1417
.s-rule.do
1386
1418
:marked
@@ -1988,8 +2020,9 @@ a(href="#toc") Back to top
1988
2020
1989
2021
.s-why
1990
2022
:marked
1991
-
**Why?** When providing the service to a top level component, that instance is shared and available to all child components of that top level component.
1992
-
2023
+
**Why?** When providing the service to a top level component,
2024
+
that instance is shared and available to all child components of that top level component.
2025
+
1993
2026
.s-why
1994
2027
:marked
1995
2028
**Why?** This is ideal when a service is sharing methods or state.
@@ -2019,8 +2052,8 @@ a(href="#toc") Back to top
2019
2052
2020
2053
.s-why
2021
2054
:marked
2022
-
**Why?** The Angular Dependency Injection (DI) mechanism resolves all dependencies
2023
-
of services based on their types declared with the services' constructors.
2055
+
**Why?** The Angular Dependency Injection (DI) mechanism resolves a service's own
2056
+
dependencies based on the declared types of that service's constructor parameters.
2024
2057
2025
2058
.s-why.s-why-last
2026
2059
:marked
@@ -2059,11 +2092,13 @@ a(href="#toc") Back to top
2059
2092
2060
2093
.s-why.s-why-last
2061
2094
:marked
2062
-
**Why?** Data service implementation may have very specific code to handle the data repository.
2063
-
This may include headers, how to talk to the data, or other services such as `Http`.
2064
-
Separating the logic into a data service encapsulates this logic in a
2065
-
single place and hides the implementation from the outside consumers
2066
-
(perhaps a component). This also makes it easier to change the implementation.
2095
+
**Why?** The details of data management, such as headers, HTTP methods,
2096
+
caching, error handling, and retry logic, are irrelevant to components
2097
+
and other data consumers.
2098
+
2099
+
A data service encapsulates these details. It's easier to evolve these
2100
+
details inside the service without affecting its consumers. And it's
2101
+
easier to test the consumers with mock service implementations.
2067
2102
2068
2103
a(href="#toc") Back to top
2069
2104
@@ -2086,8 +2121,8 @@ a(href="#toc") Back to top
2086
2121
2087
2122
.s-why.s-why-last
2088
2123
:marked
2089
-
**Why?** Lifecycle hook interfaces use strongly-typed method signatures.
2090
-
The compiler and editor can call out misspellings.
0 commit comments