mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
Improves Angular's OnPush change detection strategy for main and search history components PR Close #64570
33 lines
990 B
TypeScript
33 lines
990 B
TypeScript
/*!
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
import {ChangeDetectionStrategy, Component, effect, inject, model} from '@angular/core';
|
|
import {IS_SEARCH_DIALOG_OPEN, Search} from '@angular/docs';
|
|
import {RouterOutlet} from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'adev-main',
|
|
imports: [RouterOutlet],
|
|
template: `<router-outlet />`,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export default class MainComponent {
|
|
private readonly displaySearchDialog = inject(IS_SEARCH_DIALOG_OPEN);
|
|
private readonly searchService = inject(Search);
|
|
readonly search = model<string | undefined>('');
|
|
|
|
constructor() {
|
|
effect(() => {
|
|
const search = this.search();
|
|
if (search !== undefined) {
|
|
this.displaySearchDialog.set(true);
|
|
this.searchService.searchQuery.set(search);
|
|
}
|
|
});
|
|
}
|
|
}
|