Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 5b46b44

Browse files
docs(style-guide): copy edits
1 parent a185cc1 commit 5b46b44

File tree

1 file changed

+62
-27
lines changed

1 file changed

+62
-27
lines changed

public/docs/ts/latest/guide/style-guide.jade

+62-27
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ a(id='toc')
6363
:marked
6464
## Single Responsibility
6565

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.
6767
This helps make the app cleaner, easier to read and maintain, and more testable.
6868

6969
### <a id="01-01"></a>Rule of One
@@ -95,8 +95,8 @@ a(id='toc')
9595

9696
+makeExample('style-guide/ts/01-01/app/heroes/hero.component.avoid.ts', '', 'app/heroes/hero.component.ts')(avoid=1)
9797
:marked
98-
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.
100100

101101
+makeTabs(
102102
`style-guide/ts/01-01/main.ts,
@@ -239,20 +239,25 @@ a(href="#toc") Back to top
239239

240240
.s-rule.do
241241
:marked
242-
**Do** match the name of the symbol to the name of the file.
242+
**Do** use upper camel case for class names.
243243

244244
.s-rule.do
245245
: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.
248247

249248
.s-rule.do
250249
: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.
253257
.s-why
254258
: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.
256261

257262
- var top="vertical-align:top"
258263
table(width="100%")
@@ -340,7 +345,15 @@ a(href="#toc") Back to top
340345

341346
.s-rule.do
342347
: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.
344357

345358
.s-why
346359
:marked
@@ -1106,7 +1119,7 @@ a(href="#toc") Back to top
11061119

11071120
a(id='file-tree')
11081121
:marked
1109-
Here is a compliant folder and file structure
1122+
Here is a compliant folder and file structure:
11101123

11111124
.filetree
11121125
.file &lt;project root&gt;
@@ -1183,7 +1196,7 @@ a(href="#toc") Back to top
11831196
.s-why
11841197
:marked
11851198
**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.
11871200

11881201
.s-why
11891202
:marked
@@ -1210,7 +1223,7 @@ a(href="#toc") Back to top
12101223
**Why?** Angular modules make it easier to isolate, test, and re-use features.
12111224

12121225
.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.
12141227

12151228
a(href="#toc") Back to top
12161229
:marked
@@ -1299,7 +1312,19 @@ a(href="#toc") Back to top
12991312

13001313
.s-rule.do
13011314
: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.
13031328

13041329
.s-rule.do
13051330
:marked
@@ -1378,9 +1403,16 @@ a(href="#toc") Back to top
13781403
### <a id="04-11"></a>Core Feature Module
13791404
#### <a href="#04-11">Style 04-11</a>
13801405

1381-
.s-rule.do
1406+
.s-rule.consider
13821407
: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.
13841416

13851417
.s-rule.do
13861418
:marked
@@ -1988,8 +2020,9 @@ a(href="#toc") Back to top
19882020

19892021
.s-why
19902022
: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+
19932026
.s-why
19942027
:marked
19952028
**Why?** This is ideal when a service is sharing methods or state.
@@ -2019,8 +2052,8 @@ a(href="#toc") Back to top
20192052

20202053
.s-why
20212054
: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.
20242057

20252058
.s-why.s-why-last
20262059
:marked
@@ -2059,11 +2092,13 @@ a(href="#toc") Back to top
20592092

20602093
.s-why.s-why-last
20612094
: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.
20672102

20682103
a(href="#toc") Back to top
20692104

@@ -2086,8 +2121,8 @@ a(href="#toc") Back to top
20862121

20872122
.s-why.s-why-last
20882123
:marked
2089-
**Why?** Lifecycle hook interfaces use strongly-typed method signatures.
2090-
The compiler and editor can call out misspellings.
2124+
**Why?** Lifecycle interfaces prescribe typed method
2125+
signatures. use those signatures to flag spelling and syntax mistakes.
20912126

20922127
+makeExample('style-guide/ts/09-01/app/heroes/shared/hero-button/hero-button.component.avoid.ts', 'example', 'app/heroes/shared/hero-button/hero-button.component.ts')(avoid=1)
20932128
:marked

0 commit comments

Comments
 (0)