Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main/rules/GCI120/GCI120.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"title": "Component change detection strategy should be OnPush",
"type": "CODE_SMELL",
"code": {
"impacts": {
"RELIABILITY": ""
},
"attribute": ""
},
"status": "",
"remediation": {
"func": "",
"constantCost": ""
},
"tags": [
"creedengo",
"eco-design",
"performance"
],
"defaultSeverity": "Major",
"compatibleLanguages": [
"Angular",
]
}
42 changes: 42 additions & 0 deletions src/main/rules/GCI120/angular/GCI120.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
== Why is this an issue?

With Default change detection strategy, Angular will check this component and all its children everytime change detection runs. Any change in any part of the app, including unrelated components, will trigger re-evaluation of this components view.
It's advised to use OnPush change detection strategy, to improve performance by recuding the number of checks, limiting them to: input changes or events changes.

ps: tracked elements should be immutable.

== Non compliant Code Example

[source,angular]
----
@Component({
selector: 'my-app',
template: 'my-app.component.html',
changeDetection: ChangeDetectionStrategy.Default,
})
class MyAppComponent {
...
----

[source,angular]
----
@Component({
selector: 'my-app',
template: 'my-app.component.html',
})
class MyAppComponent {
...
----


== Compliant Solution
[source,angular]
----
@Component({
selector: 'my-app',
template: 'my-app.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
class MyAppComponent {
...
----