1
1
import { CommonModule } from "@angular/common" ;
2
- import { Component } from "@angular/core" ;
2
+ import { Component , NgZone } from "@angular/core" ;
3
3
import { takeUntilDestroyed } from "@angular/core/rxjs-interop" ;
4
4
import { FormsModule } from "@angular/forms" ;
5
- import { Subject , Subscription , debounceTime , filter } from "rxjs" ;
5
+ import { Subject , Subscription , debounceTime , distinctUntilChanged , filter } from "rxjs" ;
6
6
7
7
import { JslibModule } from "@bitwarden/angular/jslib.module" ;
8
8
import { SearchModule } from "@bitwarden/components" ;
@@ -22,13 +22,16 @@ export class VaultV2SearchComponent {
22
22
23
23
private searchText$ = new Subject < string > ( ) ;
24
24
25
- constructor ( private vaultPopupItemsService : VaultPopupItemsService ) {
25
+ constructor (
26
+ private vaultPopupItemsService : VaultPopupItemsService ,
27
+ private ngZone : NgZone ,
28
+ ) {
26
29
this . subscribeToLatestSearchText ( ) ;
27
30
this . subscribeToApplyFilter ( ) ;
28
31
}
29
32
30
33
onSearchTextChanged ( ) {
31
- this . vaultPopupItemsService . applyFilter ( this . searchText ) ;
34
+ this . searchText$ . next ( this . searchText ) ;
32
35
}
33
36
34
37
subscribeToLatestSearchText ( ) : Subscription {
@@ -44,9 +47,13 @@ export class VaultV2SearchComponent {
44
47
45
48
subscribeToApplyFilter ( ) : Subscription {
46
49
return this . searchText$
47
- . pipe ( debounceTime ( SearchTextDebounceInterval ) , takeUntilDestroyed ( ) )
50
+ . pipe ( debounceTime ( SearchTextDebounceInterval ) , distinctUntilChanged ( ) , takeUntilDestroyed ( ) )
48
51
. subscribe ( ( data ) => {
49
- this . vaultPopupItemsService . applyFilter ( data ) ;
52
+ this . ngZone . runOutsideAngular ( ( ) => {
53
+ this . ngZone . run ( ( ) => {
54
+ this . vaultPopupItemsService . applyFilter ( data ) ;
55
+ } ) ;
56
+ } ) ;
50
57
} ) ;
51
58
}
52
59
}
0 commit comments