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

Commit d78ed07

Browse files
docs(style-guide): edit copy
1 parent 397c337 commit d78ed07

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

public/docs/_examples/style-guide/ts/05-14/app/shared/toast/toast.component.avoid.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class ToastComponent implements OnInit {
77

88
private defaults = {
99
title: '',
10-
message: 'May the Force be with You'
10+
message: 'May the Force be with you'
1111
};
1212
message: string;
1313
title: string;

public/docs/_examples/style-guide/ts/05-14/app/shared/toast/toast.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ToastComponent implements OnInit {
1414
// private fields
1515
private defaults = {
1616
title: '',
17-
message: 'May the Force be with You'
17+
message: 'May the Force be with you'
1818
};
1919
private toastElement: any;
2020

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

+50-49
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ include ../_util-fns
3737
:marked
3838
## File Structure Conventions
3939

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`.
4142

4243
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.
4344

@@ -47,29 +48,29 @@ a(id='toc')
4748
:marked
4849
## Table of Contents
4950

50-
1. [Single Responsibility](#single-responsibility)
51+
1. [Single responsibility](#single-responsibility)
5152
1. [Naming](#naming)
52-
1. [Coding Conventions](#coding-conventions)
53-
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)
5455
1. [Components](#components)
5556
1. [Directives](#directives)
5657
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)
5960
1. [Appendix](#appendix)
6061

6162
.l-main-section
6263
:marked
6364
## Single Responsibility
6465

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

6869
### <a id="01-01"></a>Rule of One
6970
#### <a href="#01-01">Style 01-01</a>
7071
.s-rule.do
7172
: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.
7374

7475
.s-rule.consider
7576
:marked
@@ -85,15 +86,16 @@ a(id='toc')
8586

8687
.s-why.s-why-last
8788
: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.
8990
:marked
9091
The key is to make the code more reusable, easier to read, and less mistake prone.
9192

9293
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*.
9394

9495
+makeExample('style-guide/ts/01-01/app/heroes/hero.component.avoid.ts', '', 'app/heroes/hero.component.ts')(avoid=1)
9596
:marked
96-
Better to redistribute the component and supporting activities into their own dedicated files.
97+
Redistributing the component and supporting activities into their own dedicated files
98+
is a better practice.
9799

98100
+makeTabs(
99101
`style-guide/ts/01-01/main.ts,
@@ -203,7 +205,7 @@ a(href="#toc") Back to top
203205

204206
.s-rule.do
205207
:marked
206-
**Do** use conventional type names including `.service`, `.component`, `.pipe`, `.module`, `.directive`.
208+
**Do** use conventional type names including `.service`, `.component`, `.pipe`, `.module`, and `.directive`.
207209
Invent additional type names if you must but take care not to create too many.
208210

209211
.s-why
@@ -212,7 +214,7 @@ a(href="#toc") Back to top
212214

213215
.s-why
214216
:marked
215-
**Why?** Make it easy to find a specific file type using an editor or IDE's fuzzy search techniques.
217+
**Why?** Type names make it easy to find a specific file type using an editor or IDE's fuzzy search techniques.
216218

217219
.s-why
218220
:marked
@@ -221,7 +223,7 @@ a(href="#toc") Back to top
221223

222224
.s-why.s-why-last
223225
:marked
224-
**Why?** Provides pattern matching for any automated tasks.
226+
**Why?** Type names provide pattern matching for any automated tasks.
225227

226228
a(href="#toc") Back to top
227229

@@ -236,24 +238,20 @@ a(href="#toc") Back to top
236238

237239
.s-rule.do
238240
:marked
239-
**Do** use upper camel case for class names. Match the name of the symbol to the name of the file.
241+
**Do** match the name of the symbol to the name of the file.
240242

241243
.s-rule.do
242244
:marked
243-
**Do** append the symbol name with the conventional suffix for a thing of that type
244-
(e.g., `Component`, `Directive`, `Module`, `Pipe`, `Service`).
245+
**Do** append the symbol name with the conventional suffix for a thing of that type.
246+
For example, `Component`, `Directive`, `Module`, `Pipe`, `Service`.
245247

246248
.s-rule.do
247249
:marked
248-
**Do** give the filename the conventional suffix for a file of that type
249-
(e.g., `.component.ts`, `.directive.ts`, `.module.ts`, `.pipe.ts`, `.service.ts`).
250+
**Do** give the filename the conventional suffix for a file of that type.
251+
For example, `.component.ts`, `.directive.ts`, `.module.ts`, `.pipe.ts`, `.service.ts`.
250252
.s-why
251253
:marked
252-
**Why?** Provides a consistent way to quickly identify and reference assets.
253-
254-
.s-why.s-why-last
255-
:marked
256-
**Why?** Upper camel case is conventional for identifying objects that can be instantiated using a constructor.
254+
**Why?** Provides a conventional and consistent way to quickly identify and reference assets.
257255

258256
- var top="vertical-align:top"
259257
table(width="100%")
@@ -341,11 +339,7 @@ a(href="#toc") Back to top
341339

342340
.s-rule.do
343341
:marked
344-
**Do** use upper camel case for services.
345-
346-
.s-rule.do
347-
:marked
348-
**Do** suffix services with `Service` when it is not clear what they are (e.g. when they are nouns).
342+
**Do** suffix services with `Service` when it is not clear what they are, such as when they are nouns.
349343

350344
.s-why
351345
:marked
@@ -409,7 +403,7 @@ a(href="#toc") Back to top
409403

410404
.s-rule.avoid
411405
:marked
412-
**Avoid** putting app logic in the `main.ts`. Instead consider placing it in a component or service.
406+
**Avoid** putting app logic in the `main.ts`. Instead, consider placing it in a component or service.
413407

414408
.s-why
415409
:marked
@@ -805,7 +799,7 @@ a(href="#toc") Back to top
805799

806800
.s-why
807801
:marked
808-
**Why?** lower camel case variable names (`heroRoutes`) are easier to read and understand
802+
**Why?** Lower camel case variable names (`heroRoutes`) are easier to read and understand
809803
than the traditional UPPER_SNAKE_CASE names (`HERO_ROUTES`).
810804

811805
.s-why.s-why-last
@@ -822,7 +816,7 @@ a(href="#toc") Back to top
822816
:marked
823817
**Why?** The tradition of UPPER_SNAKE_CASE remains popular and pervasive,
824818
especially in third party modules.
825-
It is rarely worth the effort to change them or the risk of breaking existing code and documentation.
819+
It is rarely worth the effort to change them at the risk of breaking existing code and documentation.
826820

827821
+makeExample('style-guide/ts/03-02/app/core/data.service.ts', '', 'app/shared/data.service.ts')
828822
:marked
@@ -849,7 +843,7 @@ a(href="#toc") Back to top
849843
.s-why
850844
:marked
851845
**Why?** <a href="https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines" target="_blank">TypeScript guidelines</a>
852-
discourage the "I" prefix.
846+
discourage the `I` prefix.
853847

854848
.s-why
855849
:marked
@@ -946,9 +940,9 @@ a(href="#toc") Back to top
946940
All of the app's code goes in a folder named `app`.
947941
All feature areas are in their own folder, with their own Angular module.
948942

949-
All content is 1 asset per file. Each component, service, and pipe is in its own file.
950-
All 3rd party vendor scripts are stored in another folder and not in the `app` folder.
951-
You didn't write them and you don't want them cluttering app.
943+
All content is one asset per file. Each component, service, and pipe is in its own file.
944+
All third party vendor scripts are stored in another folder and not in the `app` folder.
945+
You didn't write them and you don't want them cluttering `app`.
952946
Use the naming conventions for files in this guide.
953947

954948
a(href="#toc") Back to top
@@ -1043,11 +1037,11 @@ a(href="#toc") Back to top
10431037
:marked
10441038
**Consider** configuring the IDE to hide distracting, irrelevant files such as generated `.js` and `.js.map` files.
10451039

1046-
s-why.s-why-last
1040+
.s-why.s-why-last
10471041
:marked
10481042
**Why?** No one wants to search for a file through seven levels of folders.
10491043
A flat structure is easy to scan.
1050-
1044+
10511045
On the other hand,
10521046
<a href="https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two" target="_blank">psychologists believe</a>
10531047
that humans start to struggle when the number of adjacent interesting things exceeds nine.
@@ -1099,7 +1093,7 @@ a(href="#toc") Back to top
10991093

11001094
.s-rule.consider
11011095
: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`).
11031097

11041098
.s-why
11051099
:marked
@@ -1169,7 +1163,7 @@ a(id='file-tree')
11691163

11701164
.l-sub-section
11711165
:marked
1172-
While components in dedicated folder are widely preferred,
1166+
While components in dedicated folders are widely preferred,
11731167
another option for small apps is to keep components flat (not in a dedicated folder).
11741168
This adds up to four files to the existing folder, but also reduces the folder nesting.
11751169
Whatever you choose, be consistent.
@@ -1187,7 +1181,8 @@ a(href="#toc") Back to top
11871181

11881182
.s-why
11891183
: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.
11911186

11921187
.s-why
11931188
:marked
@@ -1214,7 +1209,7 @@ a(href="#toc") Back to top
12141209
**Why?** Angular modules make it easier to isolate, test, and re-use features.
12151210

12161211
.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
12181213

12191214
a(href="#toc") Back to top
12201215
:marked
@@ -1303,7 +1298,7 @@ a(href="#toc") Back to top
13031298

13041299
.s-rule.do
13051300
: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).
13071302

13081303
.s-rule.do
13091304
:marked
@@ -1384,7 +1379,7 @@ a(href="#toc") Back to top
13841379

13851380
.s-rule.do
13861381
: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.
13881383

13891384
.s-rule.do
13901385
:marked
@@ -1431,7 +1426,7 @@ a(href="#toc") Back to top
14311426

14321427
.s-rule.do
14331428
: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.
14351430

14361431
.s-why
14371432
:marked
@@ -1692,7 +1687,7 @@ a(href="#toc") Back to top
16921687
.s-why
16931688
:marked
16941689
**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.
16961691

16971692
.s-why
16981693
:marked
@@ -1721,7 +1716,8 @@ a(href="#toc") Back to top
17211716

17221717
.s-why.s-why-last
17231718
: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.
17251721

17261722
+makeExample('style-guide/ts/05-13/app/heroes/shared/hero-button/hero-button.component.avoid.ts', 'example', 'app/heroes/shared/hero-button/hero-button.component.ts')(avoid=1)
17271723
:marked
@@ -2022,7 +2018,8 @@ a(href="#toc") Back to top
20222018

20232019
.s-why
20242020
:marked
2025-
**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.
20262023

20272024
.s-why.s-why-last
20282025
:marked
@@ -2061,7 +2058,11 @@ a(href="#toc") Back to top
20612058

20622059
.s-why.s-why-last
20632060
: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.
20652066

20662067
a(href="#toc") Back to top
20672068

@@ -2084,7 +2085,7 @@ a(href="#toc") Back to top
20842085

20852086
.s-why.s-why-last
20862087
:marked
2087-
**Why?** Strongly-typed method signatures.
2088+
**Why?** Lifecycle hook interfaces use strongly-typed method signatures.
20882089
The compiler and editor can call out misspellings.
20892090

20902091
+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)

0 commit comments

Comments
 (0)