Skip to content

Commit f3a9173

Browse files
authored
Merge pull request #3084 from eduardmarcinco/onpush/branch-2
feat: convert components to use OnPush change detection strategy
2 parents 8fad690 + ff51199 commit f3a9173

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

src/combobox/combobox.component.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
AfterContentInit,
1313
HostBinding,
1414
TemplateRef,
15-
OnDestroy
15+
OnDestroy,
16+
ChangeDetectionStrategy,
17+
ChangeDetectorRef
1618
} from "@angular/core";
1719
import { AbstractDropdownView, DropdownService } from "carbon-components-angular/dropdown";
1820
import { ListItem } from "carbon-components-angular/dropdown";
@@ -138,7 +140,6 @@ import { Observable } from "rxjs";
138140
[placeholder]="placeholder"/>
139141
@if (invalid) {
140142
<svg
141-
142143
cdsIcon="warning--filled"
143144
size="16"
144145
class="cds--list-box__invalid-icon">
@@ -222,7 +223,8 @@ import { Observable } from "rxjs";
222223
useExisting: ComboBox,
223224
multi: true
224225
}
225-
]
226+
],
227+
changeDetection: ChangeDetectionStrategy.OnPush
226228
})
227229
export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnDestroy {
228230
/**
@@ -500,7 +502,8 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
500502
constructor(
501503
protected elementRef: ElementRef,
502504
protected dropdownService: DropdownService,
503-
protected i18n: I18n
505+
protected i18n: I18n,
506+
protected cdr: ChangeDetectorRef
504507
) {}
505508

506509
/**
@@ -743,6 +746,8 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
743746
}
744747

745748
document.removeEventListener("click", this.outsideClick, true);
749+
750+
this.cdr.markForCheck();
746751
}
747752

748753
/**
@@ -766,6 +771,8 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
766771
this._dropUp = this._shouldDropUp();
767772
}
768773
}, 0);
774+
775+
this.cdr.markForCheck();
769776
}
770777

771778
/**

src/content-switcher/content-switcher.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
EventEmitter,
88
AfterViewInit,
99
HostListener,
10-
ElementRef
10+
ElementRef,
11+
ChangeDetectionStrategy
1112
} from "@angular/core";
1213
import { ContentSwitcherOption } from "./content-switcher-option.directive";
1314
import { isFocusInLastItem, isFocusInFirstItem } from "carbon-components-angular/common";
@@ -46,7 +47,8 @@ import { isFocusInLastItem, isFocusInFirstItem } from "carbon-components-angular
4647
role="tablist">
4748
<ng-content />
4849
</div>
49-
`
50+
`,
51+
changeDetection: ChangeDetectionStrategy.OnPush
5052
})
5153
export class ContentSwitcher implements AfterViewInit {
5254
@Input() ariaLabel = "content switcher";

src/context-menu/context-menu-divider.component.ts

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

33
@Component({
44
selector: "cds-context-menu-divider, ibm-context-menu-divider",
5-
template: ""
5+
template: "",
6+
changeDetection: ChangeDetectionStrategy.OnPush
67
})
78
export class ContextMenuDividerComponent {
89
@HostBinding("class.cds--menu-item-divider") dividerClass = true;

src/context-menu/context-menu-group.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
ChangeDetectionStrategy,
23
Component,
34
EventEmitter,
45
HostBinding,
@@ -17,7 +18,8 @@ import { ContextMenuSelectionService } from "./context-menu-selection.service";
1718
template: `
1819
<ng-content />
1920
`,
20-
providers: [ContextMenuSelectionService]
21+
providers: [ContextMenuSelectionService],
22+
changeDetection: ChangeDetectionStrategy.OnPush
2123
})
2224
export class ContextMenuGroupComponent implements OnInit, OnChanges, OnDestroy {
2325
@HostBinding("attr.role") role = "group";

src/context-menu/context-menu-item.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
Optional,
1111
OnInit,
1212
AfterContentInit,
13-
OnDestroy
13+
OnDestroy,
14+
ChangeDetectionStrategy
1415
} from "@angular/core";
1516
import { Subscription } from "rxjs";
1617
import { ContextMenuSelectionService } from "./context-menu-selection.service";
@@ -41,7 +42,8 @@ import { ContextMenuComponent } from "./context-menu.component";
4142
:host {
4243
grid-template-columns: 1rem 1fr max-content;
4344
}
44-
`]
45+
`],
46+
changeDetection: ChangeDetectionStrategy.OnPush
4547
})
4648
export class ContextMenuItemComponent implements OnInit, AfterContentInit, OnDestroy {
4749
@HostBinding("class.cds--menu-item") optionClass = true;

src/context-menu/context-menu.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
Input,
66
SimpleChanges,
77
OnChanges,
8-
HostBinding
8+
HostBinding,
9+
ChangeDetectionStrategy
910
} from "@angular/core";
1011

1112
/**
@@ -26,7 +27,8 @@ import {
2627
:host {
2728
display: block;
2829
}
29-
`]
30+
`],
31+
changeDetection: ChangeDetectionStrategy.OnPush
3032
})
3133
export class ContextMenuComponent implements OnChanges {
3234
@Input() open = false;

src/datepicker-input/datepicker-input.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
EventEmitter,
66
ElementRef,
77
TemplateRef,
8-
ViewChild
8+
ViewChild,
9+
ChangeDetectionStrategy
910
} from "@angular/core";
1011
import { NG_VALUE_ACCESSOR } from "@angular/forms";
1112

@@ -124,7 +125,8 @@ import { NG_VALUE_ACCESSOR } from "@angular/forms";
124125
useExisting: DatePickerInput,
125126
multi: true
126127
}
127-
]
128+
],
129+
changeDetection: ChangeDetectionStrategy.OnPush
128130
})
129131
export class DatePickerInput {
130132
private static datePickerCount = 0;

src/datepicker/datepicker.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
AfterViewInit,
1515
ViewChild,
1616
OnInit,
17-
SimpleChange
17+
SimpleChange,
18+
ChangeDetectionStrategy
1819
} from "@angular/core";
1920
import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
2021
import flatpickr from "flatpickr";
@@ -120,7 +121,8 @@ if (languages.default?.default["en"]?.weekdays) {
120121
multi: true
121122
}
122123
],
123-
encapsulation: ViewEncapsulation.None
124+
encapsulation: ViewEncapsulation.None,
125+
changeDetection: ChangeDetectionStrategy.OnPush
124126
})
125127
export class DatePicker implements
126128
OnInit,

0 commit comments

Comments
 (0)