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(search): support OnPush change detection strat #1032

Merged
merged 1 commit into from
Dec 15, 2017
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
3 changes: 2 additions & 1 deletion src/app/components/components/search/search.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, HostBinding } from '@angular/core';
import { Component, HostBinding, ChangeDetectionStrategy } from '@angular/core';

import { slideInDownAnimation } from '../../../app.animations';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'search-demo',
styleUrls: ['./search.component.scss'],
templateUrl: './search.component.html',
Expand Down
7 changes: 6 additions & 1 deletion src/platform/core/search/search-box/search-box.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, Input, Output, EventEmitter } from '@angular/core';
import { Component, ViewChild, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { trigger, state, style, transition, animate, AUTO_STYLE } from '@angular/animations';

import { TdSearchInputComponent } from '../search-input/search-input.component';
Expand All @@ -7,6 +7,7 @@ import { TdSearchInputComponent } from '../search-input/search-input.component';
selector: 'td-search-box',
templateUrl: './search-box.component.html',
styleUrls: ['./search-box.component.scss' ],
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
trigger('inputState', [
state('0', style({
Expand All @@ -29,6 +30,7 @@ export class TdSearchBoxComponent {

set value(value: any) {
this._searchInput.value = value;
this._changeDetectorRef.markForCheck();
}
get value(): any {
return this._searchInput.value;
Expand Down Expand Up @@ -101,6 +103,8 @@ export class TdSearchBoxComponent {
*/
@Output('clear') onClear: EventEmitter<void> = new EventEmitter<void>();

constructor(private _changeDetectorRef: ChangeDetectorRef) {}

/**
* Method executed when the search icon is clicked.
*/
Expand All @@ -113,6 +117,7 @@ export class TdSearchBoxComponent {

toggleVisibility(): void {
this._searchVisible = !this._searchVisible;
this._changeDetectorRef.markForCheck();
}

handleSearchDebounce(value: string): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, OnInit, Input, Output, EventEmitter, Optional } from '@angular/core';
import { Component, ViewChild, OnInit, Input, Output, EventEmitter, Optional, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { FormControl } from '@angular/forms';
import { Dir } from '@angular/cdk/bidi';
Expand All @@ -11,6 +11,7 @@ import { skip } from 'rxjs/operators/skip';
selector: 'td-search-input',
templateUrl: './search-input.component.html',
styleUrls: ['./search-input.component.scss' ],
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
trigger('searchState', [
state('hide-left', style({
Expand Down Expand Up @@ -92,7 +93,8 @@ export class TdSearchInputComponent implements OnInit {
return false;
}

constructor(@Optional() private _dir: Dir) {
constructor(@Optional() private _dir: Dir,
private _changeDetectorRef: ChangeDetectorRef) {
}

ngOnInit(): void {
Expand Down Expand Up @@ -126,6 +128,7 @@ export class TdSearchInputComponent implements OnInit {

clearSearch(): void {
this.value = '';
this._changeDetectorRef.markForCheck();
this.onClear.emit(undefined);
}

Expand Down