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

Commit 4ffad06

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

File tree

3 files changed

+54
-52
lines changed

3 files changed

+54
-52
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

+52-50
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,53 +48,55 @@ 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
7677
**Consider** limiting files to 400 lines of code.
7778

7879
.s-why
7980
:marked
80-
**Why?** One component per file makes it far easier to read, maintain, and avoid collisions with teams in source control.
81+
**Why?** One component per file makes it far easier to read, maintain, and avoid
82+
collisions with teams in source control.
8183

8284
.s-why
8385
:marked
8486
**Why?** One component per file avoids hidden bugs that often arise when combining components in a file where they may share variables, create unwanted closures, or unwanted coupling with dependencies.
8587

8688
.s-why.s-why-last
8789
:marked
88-
**Why?** A single component can be the default export for its file which facilitates lazy loading with the Router.
90+
**Why?** A single component can be the default export for its file which facilitates lazy loading with the router.
8991
:marked
9092
The key is to make the code more reusable, easier to read, and less mistake prone.
9193

9294
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*.
9395

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

98101
+makeTabs(
99102
`style-guide/ts/01-01/main.ts,
@@ -203,7 +206,7 @@ a(href="#toc") Back to top
203206

204207
.s-rule.do
205208
:marked
206-
**Do** use conventional type names including `.service`, `.component`, `.pipe`, `.module`, `.directive`.
209+
**Do** use conventional type names including `.service`, `.component`, `.pipe`, `.module`, and `.directive`.
207210
Invent additional type names if you must but take care not to create too many.
208211

209212
.s-why
@@ -212,7 +215,7 @@ a(href="#toc") Back to top
212215

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

217220
.s-why
218221
:marked
@@ -221,7 +224,7 @@ a(href="#toc") Back to top
221224

222225
.s-why.s-why-last
223226
:marked
224-
**Why?** Provides pattern matching for any automated tasks.
227+
**Why?** Type names provide pattern matching for any automated tasks.
225228

226229
a(href="#toc") Back to top
227230

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

237240
.s-rule.do
238241
:marked
239-
**Do** use upper camel case for class names. Match the name of the symbol to the name of the file.
242+
**Do** match the name of the symbol to the name of the file.
240243

241244
.s-rule.do
242245
: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`).
246+
**Do** append the symbol name with the conventional suffix for a thing of that type.
247+
For example, `Component`, `Directive`, `Module`, `Pipe`, `Service`.
245248

246249
.s-rule.do
247250
: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`).
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`.
250253
.s-why
251254
: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.
255+
**Why?** Provides a conventional and consistent way to quickly identify and reference assets.
257256

258257
- var top="vertical-align:top"
259258
table(width="100%")
@@ -341,11 +340,7 @@ a(href="#toc") Back to top
341340

342341
.s-rule.do
343342
: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).
343+
**Do** suffix services with `Service` when it is not clear what they are, such as when they are nouns.
349344

350345
.s-why
351346
:marked
@@ -409,7 +404,7 @@ a(href="#toc") Back to top
409404

410405
.s-rule.avoid
411406
:marked
412-
**Avoid** putting app logic in the `main.ts`. Instead consider placing it in a component or service.
407+
**Avoid** putting app logic in the `main.ts`. Instead, consider placing it in a component or service.
413408

414409
.s-why
415410
:marked
@@ -805,7 +800,7 @@ a(href="#toc") Back to top
805800

806801
.s-why
807802
:marked
808-
**Why?** lower camel case variable names (`heroRoutes`) are easier to read and understand
803+
**Why?** Lower camel case variable names (`heroRoutes`) are easier to read and understand
809804
than the traditional UPPER_SNAKE_CASE names (`HERO_ROUTES`).
810805

811806
.s-why.s-why-last
@@ -822,7 +817,7 @@ a(href="#toc") Back to top
822817
:marked
823818
**Why?** The tradition of UPPER_SNAKE_CASE remains popular and pervasive,
824819
especially in third party modules.
825-
It is rarely worth the effort to change them or the risk of breaking existing code and documentation.
820+
It is rarely worth the effort to change them at the risk of breaking existing code and documentation.
826821

827822
+makeExample('style-guide/ts/03-02/app/core/data.service.ts', '', 'app/shared/data.service.ts')
828823
:marked
@@ -849,7 +844,7 @@ a(href="#toc") Back to top
849844
.s-why
850845
:marked
851846
**Why?** <a href="https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines" target="_blank">TypeScript guidelines</a>
852-
discourage the "I" prefix.
847+
discourage the `I` prefix.
853848

854849
.s-why
855850
:marked
@@ -946,9 +941,9 @@ a(href="#toc") Back to top
946941
All of the app's code goes in a folder named `app`.
947942
All feature areas are in their own folder, with their own Angular module.
948943

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.
944+
All content is one asset per file. Each component, service, and pipe is in its own file.
945+
All third party vendor scripts are stored in another folder and not in the `app` folder.
946+
You didn't write them and you don't want them cluttering `app`.
952947
Use the naming conventions for files in this guide.
953948

954949
a(href="#toc") Back to top
@@ -1043,11 +1038,11 @@ a(href="#toc") Back to top
10431038
:marked
10441039
**Consider** configuring the IDE to hide distracting, irrelevant files such as generated `.js` and `.js.map` files.
10451040

1046-
s-why.s-why-last
1041+
.s-why.s-why-last
10471042
:marked
10481043
**Why?** No one wants to search for a file through seven levels of folders.
10491044
A flat structure is easy to scan.
1050-
1045+
10511046
On the other hand,
10521047
<a href="https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two" target="_blank">psychologists believe</a>
10531048
that humans start to struggle when the number of adjacent interesting things exceeds nine.
@@ -1099,7 +1094,7 @@ a(href="#toc") Back to top
10991094

11001095
.s-rule.consider
11011096
:marked
1102-
**Consider** creating a folder for a component when is has multiple accompanying files (`.ts`, `.html`, `.css` and `.spec`).
1097+
**Consider** creating a folder for a component when it has multiple accompanying files (`.ts`, `.html`, `.css` and `.spec`).
11031098

11041099
.s-why
11051100
:marked
@@ -1169,7 +1164,7 @@ a(id='file-tree')
11691164

11701165
.l-sub-section
11711166
:marked
1172-
While components in dedicated folder are widely preferred,
1167+
While components in dedicated folders are widely preferred,
11731168
another option for small apps is to keep components flat (not in a dedicated folder).
11741169
This adds up to four files to the existing folder, but also reduces the folder nesting.
11751170
Whatever you choose, be consistent.
@@ -1187,7 +1182,8 @@ a(href="#toc") Back to top
11871182

11881183
.s-why
11891184
: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.
1185+
**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.
11911187

11921188
.s-why
11931189
:marked
@@ -1214,7 +1210,7 @@ a(href="#toc") Back to top
12141210
**Why?** Angular modules make it easier to isolate, test, and re-use features.
12151211

12161212
.file-tree-reference
1217-
a(href="#file-tree") Refer here to this Folder and File Structure example
1213+
a(href="#file-tree") Refer to this Folder and File Structure example
12181214

12191215
a(href="#toc") Back to top
12201216
:marked
@@ -1303,7 +1299,7 @@ a(href="#toc") Back to top
13031299

13041300
.s-rule.do
13051301
: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).
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).
13071303

13081304
.s-rule.do
13091305
:marked
@@ -1384,7 +1380,7 @@ a(href="#toc") Back to top
13841380

13851381
.s-rule.do
13861382
: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.
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.
13881384

13891385
.s-rule.do
13901386
:marked
@@ -1431,7 +1427,7 @@ a(href="#toc") Back to top
14311427

14321428
.s-rule.do
14331429
:marked
1434-
**Do** export all symbols that from the `CoreModule` that the `AppModule` will import and make available for other feature modules to use.
1430+
**Do** export all symbols from the `CoreModule` that the `AppModule` will import and make available for other feature modules to use.
14351431

14361432
.s-why
14371433
:marked
@@ -1692,7 +1688,7 @@ a(href="#toc") Back to top
16921688
.s-why
16931689
:marked
16941690
**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.
1691+
`@Input` or `@Output`, you can modify it in a single place.
16961692

16971693
.s-why
16981694
:marked
@@ -1721,7 +1717,8 @@ a(href="#toc") Back to top
17211717

17221718
.s-why.s-why-last
17231719
: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.
1720+
**Why?** May lead to confusion when the output or the input
1721+
properties of a given directive are named one way but exported differently as a public API.
17251722

17261723
+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)
17271724
:marked
@@ -2022,7 +2019,8 @@ a(href="#toc") Back to top
20222019

20232020
.s-why
20242021
:marked
2025-
**Why?** The Angular DI mechanism resolves all dependencies of services based on their types declared with the services' constructors.
2022+
**Why?** The Angular Dependency Injection (DI) mechanism resolves all dependencies
2023+
of services based on their types declared with the services' constructors.
20262024

20272025
.s-why.s-why-last
20282026
:marked
@@ -2061,7 +2059,11 @@ a(href="#toc") Back to top
20612059

20622060
.s-why.s-why-last
20632061
: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.
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.
20652067

20662068
a(href="#toc") Back to top
20672069

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

20852087
.s-why.s-why-last
20862088
:marked
2087-
**Why?** Strongly-typed method signatures.
2089+
**Why?** Lifecycle hook interfaces use strongly-typed method signatures.
20882090
The compiler and editor can call out misspellings.
20892091

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