mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Removed nested subscribe
This commit is contained in:
@@ -207,12 +207,12 @@ describe('ComColDataService', () => {
|
|||||||
it('top level community cache refreshed', () => {
|
it('top level community cache refreshed', () => {
|
||||||
scheduler.schedule(() => (service as any).refreshCache(data));
|
scheduler.schedule(() => (service as any).refreshCache(data));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('https://rest.api/core/communities/search/top');
|
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith('https://rest.api/core/communities/search/top');
|
||||||
});
|
});
|
||||||
it('top level community without parent link, cache not refreshed', () => {
|
it('top level community without parent link, cache not refreshed', () => {
|
||||||
scheduler.schedule(() => (service as any).refreshCache(communityWithoutParentHref));
|
scheduler.schedule(() => (service as any).refreshCache(communityWithoutParentHref));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
expect(requestService.removeByHrefSubstring).not.toHaveBeenCalled();
|
expect(requestService.setStaleByHrefSubstring).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ describe('ComColDataService', () => {
|
|||||||
it('child level community cache refreshed', () => {
|
it('child level community cache refreshed', () => {
|
||||||
scheduler.schedule(() => (service as any).refreshCache(data));
|
scheduler.schedule(() => (service as any).refreshCache(data));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('a20da287-e174-466a-9926-f66as300d399');
|
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith('a20da287-e174-466a-9926-f66as300d399');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators';
|
import { distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||||
import { Observable } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||||
import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { Community } from '../shared/community.model';
|
import { Community } from '../shared/community.model';
|
||||||
@@ -116,15 +116,16 @@ export abstract class ComColDataService<T extends Community | Collection> extend
|
|||||||
if (!hasValue(parentCommunityUrl)) {
|
if (!hasValue(parentCommunityUrl)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.findByHref(parentCommunityUrl).pipe(
|
observableCombineLatest([
|
||||||
getFirstCompletedRemoteData(),
|
this.findByHref(parentCommunityUrl).pipe(
|
||||||
).subscribe((rd: RemoteData<any>) => {
|
getFirstCompletedRemoteData(),
|
||||||
|
),
|
||||||
|
this.halService.getEndpoint('communities/search/top').pipe(take(1))
|
||||||
|
]).subscribe(([rd, topHref]: [RemoteData<any>, string]) => {
|
||||||
if (rd.hasSucceeded && isNotEmpty(rd.payload) && isNotEmpty(rd.payload.id)) {
|
if (rd.hasSucceeded && isNotEmpty(rd.payload) && isNotEmpty(rd.payload.id)) {
|
||||||
this.requestService.removeByHrefSubstring(rd.payload.id);
|
this.requestService.setStaleByHrefSubstring(rd.payload.id);
|
||||||
} else {
|
} else {
|
||||||
this.halService.getEndpoint('communities/search/top')
|
this.requestService.setStaleByHrefSubstring(topHref);
|
||||||
.pipe(take(1))
|
|
||||||
.subscribe((href) => this.requestService.removeByHrefSubstring(href));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user