Task-9#8
Conversation
YurikMurik
commented
May 24, 2020
- changed searchbox logic (added debounce, filter by input value, etc.)
- changed logic of auth guard service (now it returns observables)
- created global loading block and implemented it for all requests in the app
| switchMap(() => { | ||
| return this.isAuthentificated() | ||
| .pipe( | ||
| map(auth => auth) |
There was a problem hiding this comment.
what is the point in adding this operator?
There was a problem hiding this comment.
this is an unnecessary piece of code. I deleted it
|
|
||
| public getUserInfo(): Observable<UserInfo> { | ||
| return this.http.get<UserInfo>(this.userUrl); | ||
| this.loadingBlockService.updateLoadingBlockState('start'); |
There was a problem hiding this comment.
It would be better to work with booleans instead of strings 'start' and 'finish'
| this.loadingBlockService.stateLoadingBlockNotify.subscribe( | ||
| state => { | ||
| this.loadingState = state; | ||
| this.cdref.detectChanges(); |
There was a problem hiding this comment.
why do you need this if your component uses the default change detection strategy?
There was a problem hiding this comment.
it's mistake, fixed. there is another way for subscribing on loader's component changes
| } | ||
|
|
||
| public getDataFromApi(): void { | ||
| if (this.searchInput.length === 0 || this.searchInput.length >= 3) { |
There was a problem hiding this comment.
it would be better to add this functionality with filter rxjs operator
| this.searchInputChange | ||
| .pipe(debounceTime(1000), distinctUntilChanged()) | ||
| .subscribe(result => { | ||
| this.searchInput = result; |
There was a problem hiding this comment.
why would you need this assignment?
| .pipe(debounceTime(1000), distinctUntilChanged()) | ||
| .subscribe(result => { | ||
| this.searchInput = result; | ||
| this.getDataFromApi(); |
There was a problem hiding this comment.
implement this functionality using mergeMap
| public stateLoadingBlockNotify: Observable<boolean> = this.notificationSource.asObservable(); | ||
|
|
||
| public updateLoadingBlockState(newState: string): void { | ||
| this.notificationSource.next(this.initialState); |
| }) | ||
|
|
||
| export class LoadingBlockService { | ||
| private notificationSource: Subject<boolean> = new Subject(); |
There was a problem hiding this comment.
use type of subject you can pass the initial value to