Skip to content

Commit 1703b3e

Browse files
committed
Migrate rxjs 5 to 6
1 parent a95671a commit 1703b3e

File tree

13 files changed

+259
-153
lines changed

13 files changed

+259
-153
lines changed

package-lock.json

Lines changed: 219 additions & 119 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
"karma-coverage-istanbul-reporter": "~2.0.1",
4646
"karma-jasmine": "~1.1.2",
4747
"karma-jasmine-html-reporter": "~1.3.0",
48-
"protractor": "^5.3.1",
48+
"protractor": "^5.4.0",
4949
"ts-node": "~3.3.0",
5050
"tslint": "~5.10.0",
51-
"typescript": "~2.7.2"
51+
"typescript": "~2.8.0"
5252
}
5353
}

src/app/components/status-dialog/status-dialog.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Injector, ReflectiveInjector } from '@angular/core';
33
import { AuthService } from '../../shared/services/auth.service';
44
import { StatusDialogService } from './status-dialog.service';
5-
import { Observable } from 'rxjs/Observable';
5+
import { Observable, of } from 'rxjs';
66
import { Router } from '@angular/router';
77
import { fakeAsync, tick } from '@angular/core/testing';
88
import { MockAuthService, MockRouter } from '../../shared/testing/mock-helper.spec';
@@ -27,7 +27,7 @@ describe('Service: StatusDialog', () => {
2727
});
2828

2929
it('should reload page if Hoverfly is running again', () => {
30-
authService.checkAuthenticated.and.returnValue(Observable.of(true));
30+
authService.checkAuthenticated.and.returnValue(of(true));
3131

3232
service.retry();
3333

@@ -36,7 +36,7 @@ describe('Service: StatusDialog', () => {
3636

3737
it('should do nothing if Hoverfly is down', () => {
3838

39-
authService.checkAuthenticated.and.returnValue(Observable.of(false));
39+
authService.checkAuthenticated.and.returnValue(of(false));
4040

4141
service.retry();
4242

@@ -45,7 +45,7 @@ describe('Service: StatusDialog', () => {
4545

4646
it('should navigate to dashboard from login page when Hoverfly is running again', fakeAsync(() => {
4747

48-
authService.checkAuthenticated.and.returnValue(Observable.of(true));
48+
authService.checkAuthenticated.and.returnValue(of(true));
4949
// Mocking router url
5050
router.setUrl('/login');
5151
router.navigateByUrl.and.returnValue(Promise.resolve(true));

src/app/components/status-dialog/status-dialog.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Injectable } from '@angular/core';
44
import { AuthService } from '../../shared/services/auth.service';
55
import { Router } from '@angular/router';
6+
import { filter } from 'rxjs/operators';
67
@Injectable()
78
export class StatusDialogService {
89

@@ -11,7 +12,7 @@ export class StatusDialogService {
1112

1213
retry() {
1314
this.authService.checkAuthenticated()
14-
.filter(isHealthy => isHealthy)
15+
.pipe(filter(isHealthy => isHealthy))
1516
.subscribe(() => {
1617
if (this.router.url === '/login') {
1718
this.router.navigateByUrl('/')

src/app/components/topnavbar/topnavbar.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Map } from 'immutable';
66
import { Hoverfly } from '../../shared/models/hoverfly.model';
77
import { API_ERRORS } from '../../shared/http/error-handling';
88
import { EVENT_TYPE, NotificationService } from '../notifications/notification.service';
9+
import { filter, map } from 'rxjs/operators';
910

1011
@Component({
1112
selector: 'app-topnavbar',
@@ -23,7 +24,7 @@ export class TopNavBarComponent implements OnInit {
2324

2425
ngOnInit() {
2526
this.notifyService.errors
26-
.filter(error => error === API_ERRORS.UNAUTHORIZED)
27+
.pipe(filter(error => error === API_ERRORS.UNAUTHORIZED))
2728
.subscribe(() => {
2829
this.logout()
2930
}
@@ -40,7 +41,7 @@ export class TopNavBarComponent implements OnInit {
4041

4142
// TODO resolve version before view init
4243
this.hoverfly$
43-
.map((hoverfly: Map<any, any>) => hoverfly.toJS())
44+
.pipe(map((hoverfly: Map<any, any>) => hoverfly.toJS()))
4445
.subscribe((hoverfly: Hoverfly) => {
4546
this.version = hoverfly.version || 'latest';
4647
});

src/app/shared/guards/auth.guard.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

22

33
import { Injector, ReflectiveInjector } from '@angular/core';
4-
import createSpy = jasmine.createSpy;
54
import { AuthGuard } from './auth.guard';
6-
import { Observable } from 'rxjs/Observable';
5+
import { Observable, of } from 'rxjs';
76
import { AuthService } from '../services/auth.service';
87
import { MockAuthService } from '../testing/mock-helper.spec';
98

@@ -29,7 +28,7 @@ describe('Auth Guard', () => {
2928
it('should return false if is not authenticated', () => {
3029

3130
let result;
32-
service.checkAuthenticated.and.returnValue(Observable.of(false));
31+
service.checkAuthenticated.and.returnValue(of(false));
3332

3433
authGuard.canActivate().subscribe(activated => result = activated);
3534

@@ -39,7 +38,7 @@ describe('Auth Guard', () => {
3938
it('should return true if is authenticated', () => {
4039

4140
let result;
42-
service.checkAuthenticated.and.returnValue(Observable.of(true));
41+
service.checkAuthenticated.and.returnValue(of(true));
4342

4443
authGuard.canActivate().subscribe(activated => result = activated);
4544

@@ -48,7 +47,7 @@ describe('Auth Guard', () => {
4847

4948
it('should logout if is not authenticated', () => {
5049

51-
service.checkAuthenticated.and.returnValue(Observable.of(false));
50+
service.checkAuthenticated.and.returnValue(of(false));
5251
authGuard.canActivate().subscribe();
5352

5453
expect(service.logout).toHaveBeenCalled();

src/app/shared/guards/auth.guard.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
22
import { CanActivate, Router } from '@angular/router';
33
import { Observable } from 'rxjs';
44
import { AuthService } from '../services/auth.service';
5+
import { map } from 'rxjs/operators';
56

67
@Injectable()
78
export class AuthGuard implements CanActivate {
@@ -10,11 +11,11 @@ export class AuthGuard implements CanActivate {
1011
}
1112

1213
canActivate(): Observable<boolean> {
13-
return this.service.checkAuthenticated().map((isAuthenticated: boolean) => {
14+
return this.service.checkAuthenticated().pipe(map((isAuthenticated: boolean) => {
1415
if (!isAuthenticated) {
1516
this.service.logout();
1617
}
1718
return isAuthenticated
18-
});
19+
}));
1920
}
2021
}

src/app/shared/services/auth.service.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Injectable } from '@angular/core';
22
import { Router } from '@angular/router';
3-
import { Observable } from 'rxjs';
3+
import { Observable, of } from 'rxjs';
44
import { Http, Response } from '@angular/http';
55
import { httpErrorHandler, notifyError } from '../http/error-handling';
66
import { EVENT_TYPE, NotificationService } from '../../components/notifications/notification.service';
7+
import { catchError, map } from 'rxjs/operators';
78

89
export const SESSION_API_TOKEN = 'api-token';
910

@@ -18,19 +19,20 @@ export class AuthService {
1819
checkAuthenticated(): Observable<boolean> {
1920

2021
return this.http.get('/api/v2/hoverfly/version')
21-
.map((res: Response) => res.status === 200)
22-
.catch(err => {
23-
notifyError(err, this.notifyService);
24-
return Observable.of(false);
25-
});
22+
.pipe(map((res: Response) => res.status === 200),
23+
catchError(err => {
24+
notifyError(err, this.notifyService);
25+
return of(false);
26+
})
27+
);
2628
}
2729

2830
login(username, password): void {
2931
this.http.post('/api/token-auth', {
3032
username: username,
3133
password: password
3234
})
33-
.map((res: Response) => res.json().token)
35+
.pipe(map((res: Response) => res.json().token))
3436
.subscribe(token => {
3537
sessionStorage.setItem(SESSION_API_TOKEN, token);
3638
this.notifyService.sendEvent(EVENT_TYPE.LOGIN);

src/app/shared/services/hoverfly.service.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Injectable } from '@angular/core';
22
import { Http } from '@angular/http';
3-
import { Observable , Subscription } from 'rxjs';
3+
import { Observable, Subscription, timer } from 'rxjs';
44
import { NgRedux } from '@angular-redux/store';
55
import { AppState } from '../../app.state';
66
import { Middleware } from '../models/middlware.model';
77
import { API_ERRORS, httpErrorHandler } from '../http/error-handling';
88
import { NotificationService } from '../../components/notifications/notification.service';
9+
import { filter, map } from 'rxjs/operators';
910

1011
export const HOVERFLY_ACTIONS = {
1112
UPDATE: 'UPDATE',
@@ -20,25 +21,25 @@ export class HoverflyService {
2021

2122
setMode(modeSelection): void {
2223
this.http.put('/api/v2/hoverfly/mode', JSON.stringify({ mode: modeSelection }))
23-
.map(res => res.json())
24+
.pipe(map(res => res.json()))
2425
.subscribe(
2526
this.updateHoverfly(),
2627
httpErrorHandler(this.notifyService));
2728
}
2829

2930
getHoverflyInfo(): void {
3031
this.http.get('/api/v2/hoverfly')
31-
.map(res => res.json())
32+
.pipe(map(res => res.json()))
3233
.subscribe(
3334
this.updateHoverfly(),
3435
httpErrorHandler(this.notifyService));
3536
}
3637

3738
getMiddleware(): void {
3839
this.http.get('/api/v2/hoverfly/middleware')
39-
.map(res => res.json())
40-
.filter((data: Middleware) => !!data.binary || !!data.script || !!data.remote)
41-
.map(data => new Object({ middleware: data }))
40+
.pipe(map(res => res.json()),
41+
filter((data: Middleware) => !!data.binary || !!data.script || !!data.remote),
42+
map(data => new Object({ middleware: data })))
4243
.subscribe(
4344
this.updateHoverfly(),
4445
httpErrorHandler(this.notifyService));
@@ -47,7 +48,7 @@ export class HoverflyService {
4748

4849
pollHoverfly(): Subscription {
4950

50-
return Observable.timer(0, 5000)
51+
return timer(0, 5000)
5152
.subscribe(() => {
5253
this.getHoverflyInfo();
5354
this.getMiddleware();

src/app/shared/testing/redux-helper.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Observable } from 'rxjs/Observable';
1+
import { Observable } from 'rxjs';
22
import { NgRedux } from '@angular-redux/store';
33

44
export class MockRedux extends NgRedux<any> {

0 commit comments

Comments
 (0)