From c334bbe78ead16b234c3ec79907fa6dc6ce33495 Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 31 Oct 2018 11:13:58 +0100 Subject: [PATCH] updated merged master to rxjs 6 --- .../remote-data-build.service.spec.ts | 6 ++-- .../builders/remote-data-build.service.ts | 16 +++++---- .../core/metadata/metadata.service.spec.ts | 6 ++-- src/app/core/metadata/metadata.service.ts | 35 +++++++++++-------- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/app/core/cache/builders/remote-data-build.service.spec.ts b/src/app/core/cache/builders/remote-data-build.service.spec.ts index bab628a7fe..8aea54102c 100644 --- a/src/app/core/cache/builders/remote-data-build.service.spec.ts +++ b/src/app/core/cache/builders/remote-data-build.service.spec.ts @@ -3,7 +3,7 @@ import { Item } from '../../shared/item.model'; import { PaginatedList } from '../../data/paginated-list'; import { PageInfo } from '../../shared/page-info.model'; import { RemoteData } from '../../data/remote-data'; -import { Observable } from 'rxjs/Observable'; +import { of as observableOf } from 'rxjs'; const pageInfo = new PageInfo(); const array = [ @@ -43,14 +43,14 @@ describe('RemoteDataBuildService', () => { }); it('should return the correct remoteData of a paginatedList when the input is a (remoteData of an) array', () => { - const result = (service as any).toPaginatedList(Observable.of(arrayRD), pageInfo); + const result = (service as any).toPaginatedList(observableOf(arrayRD), pageInfo); result.subscribe((resultRD) => { expect(resultRD).toEqual(expected); }); }); it('should return the correct remoteData of a paginatedList when the input is a (remoteData of a) paginated list', () => { - const result = (service as any).toPaginatedList(Observable.of(paginatedListRD), pageInfo); + const result = (service as any).toPaginatedList(observableOf(paginatedListRD), pageInfo); result.subscribe((resultRD) => { expect(resultRD).toEqual(expected); }); diff --git a/src/app/core/cache/builders/remote-data-build.service.ts b/src/app/core/cache/builders/remote-data-build.service.ts index 3a612df8a2..aa622b20c5 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -262,13 +262,15 @@ export class RemoteDataBuildService { } private toPaginatedList(input: Observable>>, pageInfo: PageInfo): Observable>> { - return input.map((rd: RemoteData>) => { - if (Array.isArray(rd.payload)) { - return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload) }) - } else { - return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload.page) }); - } - }); + return input.pipe( + map((rd: RemoteData>) => { + if (Array.isArray(rd.payload)) { + return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload) }) + } else { + return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload.page) }); + } + }) + ); } } diff --git a/src/app/core/metadata/metadata.service.spec.ts b/src/app/core/metadata/metadata.service.spec.ts index 1493a543f1..2456ae9e55 100644 --- a/src/app/core/metadata/metadata.service.spec.ts +++ b/src/app/core/metadata/metadata.service.spec.ts @@ -32,9 +32,7 @@ import { MockItem } from '../../shared/mocks/mock-item'; import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader'; import { BrowseService } from '../browse/browse.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; -import { PaginatedList } from '../data/paginated-list'; -import { PageInfo } from '../shared/page-info.model'; -import { EmptyError } from 'rxjs/util/EmptyError'; +import { EmptyError } from 'rxjs/internal-compatibility'; /* tslint:disable:max-classes-per-file */ @Component({ @@ -185,7 +183,7 @@ describe('MetadataService', () => { describe('when the item has no bitstreams', () => { beforeEach(() => { - spyOn(MockItem, 'getFiles').and.returnValue(Observable.of([])); + spyOn(MockItem, 'getFiles').and.returnValue(observableOf([])); }); it('processRemoteData should not produce an EmptyError', fakeAsync(() => { diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index 3c2302b03f..3a63be3f55 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -1,4 +1,4 @@ -import { distinctUntilKeyChanged, filter, first, map, take } from 'rxjs/operators'; +import { catchError, distinctUntilKeyChanged, filter, first, map, take } from 'rxjs/operators'; import { Inject, Injectable } from '@angular/core'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; @@ -52,8 +52,8 @@ export class MetadataService { route = this.getCurrentRoute(route); return { params: route.params, data: route.data }; }),).subscribe((routeInfo: any) => { - this.processRouteChange(routeInfo); - }); + this.processRouteChange(routeInfo); + }); } public processRemoteData(remoteData: Observable>): void { @@ -260,20 +260,25 @@ export class MetadataService { if (this.currentObject.value instanceof Item) { const item = this.currentObject.value as Item; item.getFiles() - .first((files) => isNotEmpty(files)) - .catch((error) => { console.debug(error); return [] }) + .pipe( + first((files) => isNotEmpty(files)), + catchError((error) => { + console.debug(error); + return [] + })) .subscribe((bitstreams: Bitstream[]) => { for (const bitstream of bitstreams) { - bitstream.format.first() - .map((rd: RemoteData) => rd.payload) - .filter((format: BitstreamFormat) => hasValue(format)) - .subscribe((format: BitstreamFormat) => { - if (format.mimetype === 'application/pdf') { - this.addMetaTag('citation_pdf_url', bitstream.content); - } - }); - } - }); + bitstream.format.pipe( + first(), + map((rd: RemoteData) => rd.payload), + filter((format: BitstreamFormat) => hasValue(format))) + .subscribe((format: BitstreamFormat) => { + if (format.mimetype === 'application/pdf') { + this.addMetaTag('citation_pdf_url', bitstream.content); + } + }); + } + }); } }