Skip to content

Commit b2368b7

Browse files
authored
Merge pull request #3083 from eduardmarcinco/onpush/batch-1
feat: convert components to use OnPush change detection strategy
2 parents f3a9173 + c367c9e commit b2368b7

File tree

8 files changed

+35
-19
lines changed

8 files changed

+35
-19
lines changed

src/accordion/accordion-item.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
HostBinding,
55
Output,
66
TemplateRef,
7-
EventEmitter
7+
EventEmitter,
8+
ChangeDetectionStrategy
89
} from "@angular/core";
910

1011
@Component({
@@ -46,7 +47,8 @@ import {
4647
:host {
4748
display: list-item;
4849
}
49-
`]
50+
`],
51+
changeDetection: ChangeDetectionStrategy.OnPush
5052
})
5153
export class AccordionItem {
5254
static accordionItemCount = 0;

src/accordion/accordion.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
Input,
44
ContentChildren,
55
QueryList,
6-
AfterContentInit
6+
AfterContentInit,
7+
ChangeDetectionStrategy
78
} from "@angular/core";
89
import { AccordionItem } from "./accordion-item.component";
910

@@ -33,7 +34,8 @@ import { AccordionItem } from "./accordion-item.component";
3334
role="list">
3435
<ng-content />
3536
</div>
36-
`
37+
`,
38+
changeDetection: ChangeDetectionStrategy.OnPush
3739
})
3840
export class Accordion implements AfterContentInit {
3941
/**

src/breadcrumb/breadcrumb-item.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ import {
44
Input,
55
Output,
66
EventEmitter,
7-
Optional
7+
Optional,
8+
ChangeDetectionStrategy
89
} from "@angular/core";
910
import { DomSanitizer } from "@angular/platform-browser";
1011
import { Router } from "@angular/router";
1112

1213
@Component({
1314
selector: "cds-breadcrumb-item, ibm-breadcrumb-item",
1415
template: `
16+
<ng-template #content>
17+
<ng-content />
18+
</ng-template>
19+
1520
@if (useTemplate()) {
1621
<a
1722
class="cds--link"
@@ -21,9 +26,10 @@ import { Router } from "@angular/router";
2126
<ng-container *ngTemplateOutlet="content" />
2227
</a>
2328
} @else {
24-
<ng-content />
29+
<ng-container *ngTemplateOutlet="content" />
2530
}
26-
`
31+
`,
32+
changeDetection: ChangeDetectionStrategy.OnPush
2733
})
2834
export class BreadcrumbItemComponent {
2935
@Input() set href(v: string) {

src/breadcrumb/breadcrumb.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
TemplateRef,
88
Optional,
99
Output,
10-
EventEmitter
10+
EventEmitter,
11+
ChangeDetectionStrategy
1112
} from "@angular/core";
1213

1314
import { BreadcrumbItem } from "./breadcrumb-item.interface";
@@ -121,7 +122,8 @@ const MINIMUM_OVERFLOW_THRESHOLD = 4;
121122
}
122123
}
123124
</nav>
124-
`
125+
`,
126+
changeDetection: ChangeDetectionStrategy.OnPush
125127
})
126128
export class Breadcrumb implements AfterContentInit {
127129
@ContentChildren(BreadcrumbItemComponent) children: QueryList<BreadcrumbItemComponent>;

src/button/base-icon-button.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input } from "@angular/core";
1+
import { ChangeDetectionStrategy, Component, Input } from "@angular/core";
22

33
/**
44
* Base button with common input properties for configuring icon button.
@@ -7,7 +7,8 @@ import { Component, Input } from "@angular/core";
77
* Used by pagination nav icon button, code snippet, etc.
88
*/
99
@Component({
10-
template: ""
10+
template: "",
11+
changeDetection: ChangeDetectionStrategy.OnPush
1112
})
1213
export class BaseIconButton {
1314
/**

src/button/button-set.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, HostBinding } from "@angular/core";
1+
import { ChangeDetectionStrategy, Component, HostBinding } from "@angular/core";
22

33
/**
44
* Get started with importing the module:
@@ -11,7 +11,8 @@ import { Component, HostBinding } from "@angular/core";
1111
*/
1212
@Component({
1313
selector: "cds-button-set, ibm-button-set",
14-
template: "<ng-content />"
14+
template: "<ng-content />",
15+
changeDetection: ChangeDetectionStrategy.OnPush
1516
})
1617
export class ButtonSet {
1718
@HostBinding("class.cds--btn-set") buttonSetClass = true;

src/button/icon-button.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
AfterViewInit,
3+
ChangeDetectionStrategy,
34
Component,
45
ElementRef,
56
EventEmitter,
@@ -53,7 +54,8 @@ import { ButtonSize, ButtonType } from "./button.types";
5354
<ng-content />
5455
</button>
5556
</cds-tooltip>
56-
`
57+
`,
58+
changeDetection: ChangeDetectionStrategy.OnPush
5759
})
5860
export class IconButton extends BaseIconButton implements AfterViewInit {
5961
/**

src/code-snippet/code-snippet.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
HostBinding,
55
ViewChild,
66
AfterViewInit,
7-
OnInit
7+
OnInit,
8+
ChangeDetectionStrategy
89
} from "@angular/core";
910

1011
import { I18n } from "carbon-components-angular/i18n";
@@ -66,9 +67,7 @@ export enum SnippetType {
6667
}
6768
}
6869
@if (!skeleton) {
69-
<pre #codeContent (scroll)="(display === 'multi' ? handleScroll() : null)">
70-
<code #code><ng-container *ngTemplateOutlet="codeTemplate" /></code>
71-
</pre>
70+
<pre #codeContent (scroll)="(display === 'multi' ? handleScroll() : null)"><code #code><ng-container *ngTemplateOutlet="codeTemplate" /></code></pre>
7271
}
7372
</div>
7473
@if (hasLeft) {
@@ -135,7 +134,8 @@ export enum SnippetType {
135134
<ng-template #codeTemplate>
136135
<ng-content />
137136
</ng-template>
138-
`
137+
`,
138+
changeDetection: ChangeDetectionStrategy.OnPush
139139
})
140140
export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit {
141141
@HostBinding("class.cds--snippet") get snippetClass() {

0 commit comments

Comments
 (0)