Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
X-tee
X-Road-catalogue
Commits
76b386e4
Commit
76b386e4
authored
Mar 19, 2019
by
Vitali Stupin
Browse files
Debouncing search while typing filter
parent
feb028cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/app/config.ts
View file @
76b386e4
...
...
@@ -11,3 +11,4 @@ export const LANGUAGES = {
ENG
:
'
eng
'
};
export
const
PREVIEW_SIZE
=
5
;
export
const
FILTER_DEBOUNCE
=
200
;
src/app/subsystem-list/search/search.component.ts
View file @
76b386e4
...
...
@@ -7,12 +7,11 @@ import { SubsystemsService } from '../../subsystems.service';
styleUrls
:
[
'
./search.component.css
'
]
})
export
class
SearchComponent
implements
OnInit
{
limit
:
string
;
nonEmpty
:
boolean
;
filter
:
string
;
constructor
(
private
subsystemsService
:
SubsystemsService
)
{
}
constructor
(
private
subsystemsService
:
SubsystemsService
)
{}
setNonEmpty
(
nonEmpty
:
boolean
)
{
this
.
subsystemsService
.
setNonEmpty
(
nonEmpty
);
...
...
src/app/subsystems.service.ts
View file @
76b386e4
import
{
Injectable
,
Output
,
EventEmitter
}
from
'
@angular/core
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
import
{
Observable
,
of
,
BehaviorSubject
}
from
'
rxjs
'
;
import
{
catchError
}
from
'
rxjs/operators
'
;
import
{
Observable
,
of
,
BehaviorSubject
,
Subject
}
from
'
rxjs
'
;
import
{
catchError
,
debounceTime
,
distinctUntilChanged
}
from
'
rxjs/operators
'
;
import
{
Subsystem
}
from
'
./subsystem
'
;
import
{
Method
}
from
'
./method
'
;
import
{
MAX_LIMIT
,
DEFAULT_LIMIT
,
INSTANCES
,
API_SERVICE
}
from
'
./config
'
;
import
{
MAX_LIMIT
,
DEFAULT_LIMIT
,
INSTANCES
,
API_SERVICE
,
FILTER_DEBOUNCE
}
from
'
./config
'
;
@
Injectable
({
providedIn
:
'
root
'
...
...
@@ -17,10 +17,19 @@ export class SubsystemsService {
private
instance
=
''
;
subsystemsSubject
:
BehaviorSubject
<
Subsystem
[]
>
=
new
BehaviorSubject
([]);
filteredSubsystemsSubject
:
BehaviorSubject
<
Subsystem
[]
>
=
new
BehaviorSubject
([]);
private
updateFilter
=
new
Subject
<
string
>
();
@
Output
()
warnings
:
EventEmitter
<
string
>
=
new
EventEmitter
();
constructor
(
private
http
:
HttpClient
)
{}
constructor
(
private
http
:
HttpClient
)
{
// Debouncing update of filter
this
.
updateFilter
.
pipe
(
debounceTime
(
FILTER_DEBOUNCE
),
distinctUntilChanged
()
).
subscribe
(()
=>
{
this
.
updateFiltered
();
});
}
private
filteredSubsystems
():
Subsystem
[]
{
const
filtered
:
Subsystem
[]
=
[];
...
...
@@ -178,7 +187,8 @@ export class SubsystemsService {
setFilter
(
filter
:
string
)
{
if
(
this
.
filter
!==
filter
.
trim
())
{
this
.
filter
=
filter
.
trim
();
this
.
updateFiltered
();
// Debouncing update of filter
this
.
updateFilter
.
next
(
this
.
filter
);
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment