chore: add guidance on getters/setters to coding standards (#7977)

This commit is contained in:
Jeremy Elbourn
2017-11-21 09:02:14 -08:00
committed by GitHub
parent 179445c6ab
commit 70aa3c2fa6
+18
View File
@@ -154,6 +154,24 @@ be part of the user-facing API. This typically applies to symbols used in templa
Additionally, the `@docs-private` JsDoc annotation can be used to hide any symbol from the public
API docs.
#### Getters and Setters
* Avoid long or complex getters and setters. If the logic of an accessor would take more than
three lines, introduce a new method to contain the logic.
* A getter should immediately precede its corresponding setter.
* Decorators such as `@Input` should be applied to the getter and not the setter.
* Always use a `readonly` property instead of a getter (with no setter) when possible.
```ts
/** YES */
readonly active: boolean;
/** NO */
get active(): boolean {
// Using a getter solely to make the property read-only.
return this._active;
}
```
#### JsDoc comments
All public APIs must have user-facing comments. These are extracted and shown in the documentation