Skip to content

Commit 3fb4632

Browse files
refactor: use searchbox debounce
1 parent 02e5183 commit 3fb4632

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

projects/components/src/table/controls/table-controls.component.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ describe('Table Controls component', () => {
5353
});
5454

5555
spectator.triggerEventHandler(SearchBoxComponent, 'valueChange', 'testing');
56-
spectator.tick(200);
57-
58-
expect(onChangeSpy).not.toHaveBeenCalledWith('testing');
59-
// 400 ms debounce
60-
spectator.tick(200);
6156
expect(onChangeSpy).toHaveBeenCalledWith('testing');
6257
}));
6358

projects/components/src/table/controls/table-controls.component.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
Output
1010
} from '@angular/core';
1111
import { IconType } from '@hypertrace/assets-library';
12-
import { SubscriptionLifecycle, TypedSimpleChanges } from '@hypertrace/common';
13-
import { Subject } from 'rxjs';
14-
import { debounceTime } from 'rxjs/operators';
12+
import { TypedSimpleChanges } from '@hypertrace/common';
1513
import { IconSize } from '../../icon/icon-size';
1614
import { MultiSelectJustify } from '../../multi-select/multi-select-justify';
1715
import { MultiSelectSearchMode, TriggerLabelDisplayMode } from '../../multi-select/multi-select.component';
@@ -27,7 +25,6 @@ import {
2725
@Component({
2826
selector: 'ht-table-controls',
2927
styleUrls: ['./table-controls.component.scss'],
30-
providers: [SubscriptionLifecycle],
3128
changeDetection: ChangeDetectionStrategy.OnPush,
3229
template: `
3330
<div class="table-controls" *ngIf="this.anyControlsEnabled">
@@ -38,6 +35,7 @@ import {
3835
*ngIf="this.searchEnabled"
3936
class="control search-box"
4037
[placeholder]="this.searchPlaceholder || this.DEFAULT_SEARCH_PLACEHOLDER"
38+
[debounceTime]="400"
4139
(valueChange)="this.onSearchChange($event)"
4240
></ht-search-box>
4341
@@ -152,17 +150,8 @@ export class TableControlsComponent implements OnChanges {
152150
return !!this.searchEnabled || this.viewToggleEnabled || this.selectControlsEnabled || this.checkboxControlsEnabled;
153151
}
154152

155-
private readonly searchDebounceSubject: Subject<string> = new Subject<string>();
156-
157-
public constructor(
158-
private readonly subscriptionLifecycle: SubscriptionLifecycle,
159-
private readonly differFactory: IterableDiffers
160-
) {
153+
public constructor(private readonly differFactory: IterableDiffers) {
161154
this.checkboxDiffer = this.differFactory.find([]).create();
162-
163-
this.subscriptionLifecycle.add(
164-
this.searchDebounceSubject.pipe(debounceTime(400)).subscribe(text => this.searchChange.emit(text))
165-
);
166155
}
167156

168157
public ngOnChanges(changes: TypedSimpleChanges<this>): void {
@@ -208,7 +197,7 @@ export class TableControlsComponent implements OnChanges {
208197
}
209198

210199
public onSearchChange(text: string): void {
211-
this.searchDebounceSubject.next(text);
200+
this.searchChange.emit(text);
212201
}
213202

214203
public onMultiSelectChange(select: TableSelectControl, selections: TableSelectControlOption[]): void {

0 commit comments

Comments
 (0)