Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert components to use OnPush change detection strategy #3083

Merged
merged 7 commits into from
Dec 17, 2024
Merged
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
6 changes: 4 additions & 2 deletions src/accordion/accordion-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
HostBinding,
Output,
TemplateRef,
EventEmitter
EventEmitter,
ChangeDetectionStrategy
} from "@angular/core";

@Component({
Expand Down Expand Up @@ -46,7 +47,8 @@ import {
:host {
display: list-item;
}
`]
`],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AccordionItem {
static accordionItemCount = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/accordion/accordion.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
Input,
ContentChildren,
QueryList,
AfterContentInit
AfterContentInit,
ChangeDetectionStrategy
} from "@angular/core";
import { AccordionItem } from "./accordion-item.component";

Expand Down Expand Up @@ -33,7 +34,8 @@ import { AccordionItem } from "./accordion-item.component";
role="list">
<ng-content />
</div>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class Accordion implements AfterContentInit {
/**
Expand Down
12 changes: 9 additions & 3 deletions src/breadcrumb/breadcrumb-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import {
Input,
Output,
EventEmitter,
Optional
Optional,
ChangeDetectionStrategy
} from "@angular/core";
import { DomSanitizer } from "@angular/platform-browser";
import { Router } from "@angular/router";

@Component({
selector: "cds-breadcrumb-item, ibm-breadcrumb-item",
template: `
<ng-template #content>
<ng-content />
</ng-template>

@if (useTemplate()) {
<a
class="cds--link"
Expand All @@ -21,9 +26,10 @@ import { Router } from "@angular/router";
<ng-container *ngTemplateOutlet="content" />
</a>
} @else {
<ng-content />
<ng-container *ngTemplateOutlet="content" />
}
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class BreadcrumbItemComponent {
@Input() set href(v: string) {
Expand Down
6 changes: 4 additions & 2 deletions src/breadcrumb/breadcrumb.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
TemplateRef,
Optional,
Output,
EventEmitter
EventEmitter,
ChangeDetectionStrategy
} from "@angular/core";

import { BreadcrumbItem } from "./breadcrumb-item.interface";
Expand Down Expand Up @@ -121,7 +122,8 @@ const MINIMUM_OVERFLOW_THRESHOLD = 4;
}
}
</nav>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class Breadcrumb implements AfterContentInit {
@ContentChildren(BreadcrumbItemComponent) children: QueryList<BreadcrumbItemComponent>;
Expand Down
5 changes: 3 additions & 2 deletions src/button/base-icon-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input } from "@angular/core";
import { ChangeDetectionStrategy, Component, Input } from "@angular/core";

/**
* Base button with common input properties for configuring icon button.
Expand All @@ -7,7 +7,8 @@ import { Component, Input } from "@angular/core";
* Used by pagination nav icon button, code snippet, etc.
*/
@Component({
template: ""
template: "",
changeDetection: ChangeDetectionStrategy.OnPush
})
export class BaseIconButton {
/**
Expand Down
5 changes: 3 additions & 2 deletions src/button/button-set.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, HostBinding } from "@angular/core";
import { ChangeDetectionStrategy, Component, HostBinding } from "@angular/core";

/**
* Get started with importing the module:
Expand All @@ -11,7 +11,8 @@ import { Component, HostBinding } from "@angular/core";
*/
@Component({
selector: "cds-button-set, ibm-button-set",
template: "<ng-content />"
template: "<ng-content />",
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ButtonSet {
@HostBinding("class.cds--btn-set") buttonSetClass = true;
Expand Down
4 changes: 3 additions & 1 deletion src/button/icon-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
Expand Down Expand Up @@ -53,7 +54,8 @@ import { ButtonSize, ButtonType } from "./button.types";
<ng-content />
</button>
</cds-tooltip>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class IconButton extends BaseIconButton implements AfterViewInit {
/**
Expand Down
10 changes: 5 additions & 5 deletions src/code-snippet/code-snippet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
HostBinding,
ViewChild,
AfterViewInit,
OnInit
OnInit,
ChangeDetectionStrategy
} from "@angular/core";

import { I18n } from "carbon-components-angular/i18n";
Expand Down Expand Up @@ -66,9 +67,7 @@ export enum SnippetType {
}
}
@if (!skeleton) {
<pre #codeContent (scroll)="(display === 'multi' ? handleScroll() : null)">
<code #code><ng-container *ngTemplateOutlet="codeTemplate" /></code>
</pre>
<pre #codeContent (scroll)="(display === 'multi' ? handleScroll() : null)"><code #code><ng-container *ngTemplateOutlet="codeTemplate" /></code></pre>
}
</div>
@if (hasLeft) {
Expand Down Expand Up @@ -135,7 +134,8 @@ export enum SnippetType {
<ng-template #codeTemplate>
<ng-content />
</ng-template>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit {
@HostBinding("class.cds--snippet") get snippetClass() {
Expand Down
Loading