Skip to content

Commit 80e7711

Browse files
fix: avoid extra emit on deep link (#1538)
* fix: avoid extra emit on deep link * test: update test
1 parent a59b711 commit 80e7711

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

projects/common/src/time/time-range.service.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ describe('Time range(TR) service', () => {
7878
}
7979
} as unknown) as ActivatedRoute
8080
}),
81-
getQueryParameter: jest
82-
.fn()
83-
.mockReturnValueOnce(firstArrivingTimeRange.toUrlString())
84-
.mockReturnValue(secondArrivingTimeRange.toUrlString()),
81+
getQueryParameter: jest.fn().mockReturnValue(secondArrivingTimeRange.toUrlString()),
8582
getCurrentActivatedRoute: () =>
8683
(({ snapshot: { queryParams: { time: 'test-value' } } } as unknown) as ActivatedRoute)
8784
})
@@ -92,8 +89,8 @@ describe('Time range(TR) service', () => {
9289

9390
expect(() => spectator.service.getCurrentTimeRange()).toThrow();
9491

95-
expectObservable(recordedTimeRanges).toBe('-x----y', {
96-
x: new FixedTimeRange(new Date(1573255100253), new Date(1573255111159)),
92+
expectObservable(recordedTimeRanges).toBe('-x---y', {
93+
x: firstArrivingTimeRange,
9794
y: secondArrivingTimeRange
9895
});
9996
});

projects/common/src/time/time-range.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Injectable } from '@angular/core';
22
import { ParamMap } from '@angular/router';
33
import { isEmpty, isNil, omit } from 'lodash-es';
4-
import { concat, EMPTY, Observable, ReplaySubject } from 'rxjs';
5-
import { catchError, distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators';
4+
import { EMPTY, Observable, ReplaySubject } from 'rxjs';
5+
import { catchError, distinctUntilChanged, filter, map, skip, switchMap, take } from 'rxjs/operators';
66
import { NavigationService, QueryParamObject } from '../navigation/navigation.service';
77
import { ReplayObservable } from '../utilities/rxjs/rxjs-utils';
88
import { FixedTimeRange } from './fixed-time-range';
@@ -80,8 +80,9 @@ export class TimeRangeService {
8080
private getPageTimeRangeChanges(): Observable<TimeRange> {
8181
return this.navigationService.navigation$.pipe(
8282
map(activeRoute => activeRoute.snapshot.queryParamMap),
83-
filter(queryParamMap => !isNil(queryParamMap.get(TimeRangeService.TIME_RANGE_QUERY_PARAM))),
8483
distinctUntilChanged((prevParamMap, currParamMap) => this.shouldNotUpdateTimeRange(prevParamMap, currParamMap)),
84+
skip(1), // Skip the first nav, this is handled by initializeTimeRange, but we want to populate prev for distinctUntilChanged
85+
filter(queryParamMap => queryParamMap.has(TimeRangeService.TIME_RANGE_QUERY_PARAM)),
8586
map(currQueryParamMap => {
8687
const timeRangeQueryParamString = currQueryParamMap.get(TimeRangeService.TIME_RANGE_QUERY_PARAM);
8788

@@ -91,7 +92,9 @@ export class TimeRangeService {
9192
}
9293

9394
private initializeTimeRange(): void {
94-
concat(this.getInitialTimeRange(), this.getPageTimeRangeChanges()).subscribe(timeRange => {
95+
this.getInitialTimeRange().subscribe(timeRangeFromInitialUrl => this.applyTimeRangeChange(timeRangeFromInitialUrl));
96+
97+
this.getPageTimeRangeChanges().subscribe(timeRange => {
9598
if (!this.timeRangeMatchesCurrentUrl(timeRange)) {
9699
this.setTimeRangeInUrl(timeRange);
97100
} else {

0 commit comments

Comments
 (0)