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

Commit f3169a5

Browse files
committed
more names
1 parent 7bcb535 commit f3169a5

File tree

1 file changed

+53
-35
lines changed

1 file changed

+53
-35
lines changed

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

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ a(id='toc')
7575

7676
<a href="#toc">Back to top</a>
7777
:marked
78-
## File Naming
79-
80-
### File Naming Guidelines
81-
<a id="02-01"></a>
82-
#### Style 02-01
78+
## Naming
8379

8480
- Use consistent names for all components following a pattern that describes the component's feature then (optionally) its type. My recommended pattern is `feature.type.js`. There are 2 names for most assets:
8581
* the file name (`avengers.component.ts`)
@@ -93,7 +89,7 @@ a(id='toc')
9389

9490
<a href="#toc">Back to top</a>
9591
:marked
96-
### Separate with Dots and Dashes
92+
### Separate File Names with Dots and Dashes
9793
<a id="02-01"></a>
9894
#### Style 02-01
9995

@@ -111,58 +107,80 @@ a(id='toc')
111107

112108
<a href="#toc">Back to top</a>
113109
:marked
114-
### Component Names
115-
<a id="02-03"></a>
116-
#### Style 02-03
110+
### Names
111+
<a id="02-02"></a>
112+
#### Style 02-02
117113

118-
- Use consistent names for all components named after their feature. Use UpperCamelCase for components' symbols. Match the name of the component to the naming of the file
114+
- Use consistent names for all assets named after what they represent.
115+
116+
- Use UpperCamelCase for symbols. Match the name of the symbol to the naming of the file.
119117

120-
**Why?** Provides a consistent way to quickly identify and reference components.
118+
- Append the symbol name with a suffix that it represents.
119+
120+
**Why?** Provides a consistent way to quickly identify and reference assets.
121121

122122
**Why?** UpperCamelCase is conventional for identifying object that can be instantiated using a constructor.
123123

124+
**Why?** The `Component` suffix is more commonly used and is more explicitly descriptive.
125+
124126
```typescript
125-
AppComponent //app.component.ts
126-
HeroesComponent //heroes.component.ts
127-
HeroListComponent //hero-list.component.ts
128-
HeroDetailComponent //hero-detail.component.ts
127+
/* recommended */
128+
AppComponent // app.component.ts
129+
HeroesComponent // heroes.component.ts
130+
HeroListComponent // hero-list.component.ts
131+
HeroDetailComponent // hero-detail.component.ts
132+
133+
/* recommended */
134+
ValidationDirective // validation.directive.ts
129135
```
130136

131137
<a href="#toc">Back to top</a>
132138
:marked
133-
### Suffixes
134-
<a id="02-04"></a>
135-
#### Style 02-04
139+
### Service Names
140+
<a id="02-03"></a>
141+
#### Style 02-03
136142

137-
- Append the component name with the suffix `Component`.
143+
- Use consistent names for all services named after their feature. Use UpperCamelCase for services. Suffix services with `Service` when it is not clear what they are (e.g. when they are nouns).
138144

139-
**Why?** The `Component` suffix is more commonly used and is more explicitly descriptive.
145+
**Why?** Provides a consistent way to quickly identify and reference services.
140146

141-
```typescript
142-
// recommended
147+
**Why?** Clear service names such as `logger` do not require a suffix.
148+
149+
**Why?** Service names such as `Credit` are nouns and require a suffix and should be named with a suffix when it is not obvious if it is a service or something else.
143150

144-
// hero-list.component.ts
145-
export class HeroListComponent { }
151+
```typescript
152+
HeroDataService // hero-data.service.ts
153+
CreditService // credit.service.ts
154+
LoggerService // logger.service.ts
146155
```
147156

148157
<a href="#toc">Back to top</a>
149158
:marked
150-
### Service Names
151-
<a id="02-10"></a>
152-
#### Style 02-10
159+
### Bootstrapping
160+
<a id="02-04"></a>
161+
#### Style 02-04
153162

154-
- Use consistent names for all services named after their feature. Use UpperCamelCase for services. Suffix services with `Service` when it is not clear what they are (e.g. when they are nouns).
163+
- Place bootstrapping and platform logic for the app in a file named `main.ts`.
164+
165+
- Do not put app logic in the `main.ts`. Instead consider placing it in a Component or Service.
166+
167+
**Why?** Follows a consistent convention for the startup logic of an app.
155168

156-
**Why?** Provides a consistent way to quickly identify and reference services.
169+
**Why?** Follows a familar convention from other technology platforms.
157170

158-
**Why?** Clear service names such as `logger` do not require a suffix.
171+
<a href="#toc">Back to top</a>
172+
:marked
173+
### Pipe Names
174+
<a id="02-10"></a>
175+
#### Style 02-10
159176

160-
**Why?** Service names such as `Credit` are nouns and require a suffix and should be named with a suffix when it is not obvious if it is a service or something else.
177+
- Use consistent names for all pipes named after their feature.
178+
179+
**Why?** Provides a consistent way to quickly identify and reference pipes.
161180

162181
```typescript
163-
HeroService // hero.service.ts
164-
CreditService // credit.service.ts
165-
Logger // logger.service.ts
182+
EllipsisPipe // ellipsis.pipe.ts
183+
InitCapsPipe // init-caps.pipe.ts
166184
```
167185

168186
<a href="#toc">Back to top</a>
@@ -171,7 +189,7 @@ a(id='toc')
171189
<a id="02-12"></a>
172190
#### Style 02-12
173191

174-
- Name test specifications similar to the component they test with a suffix of `spec`.
192+
- Name test specifications similar to the component they test with a suffix of `.spec`.
175193

176194
**Why?** Provides a consistent way to quickly identify components.
177195

0 commit comments

Comments
 (0)