mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Merge branch 'fix-mutliple-api-calls-on-route-change-7.6' into fix-mutliple-api-calls-on-route-change
This commit is contained in:
@@ -63,16 +63,18 @@ describe('ServerCheckGuard', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe(`listenForRouteChanges`, () => {
|
describe(`listenForRouteChanges`, () => {
|
||||||
it(`should invalidate the root cache on every NavigationStart event`, () => {
|
it(`should invalidate the root cache when the method is first called, and then on every NavigationStart event`, () => {
|
||||||
testScheduler.run(() => {
|
testScheduler.run(() => {
|
||||||
guard.listenForRouteChanges();
|
guard.listenForRouteChanges();
|
||||||
|
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
eventSubject.next(new NavigationStart(1,''));
|
eventSubject.next(new NavigationStart(1,''));
|
||||||
eventSubject.next(new NavigationEnd(1,'', ''));
|
eventSubject.next(new NavigationEnd(1,'', ''));
|
||||||
eventSubject.next(new NavigationStart(2,''));
|
eventSubject.next(new NavigationStart(2,''));
|
||||||
eventSubject.next(new NavigationEnd(2,'', ''));
|
eventSubject.next(new NavigationEnd(2,'', ''));
|
||||||
eventSubject.next(new NavigationStart(3,''));
|
eventSubject.next(new NavigationStart(3,''));
|
||||||
});
|
});
|
||||||
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(3);
|
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -52,6 +52,10 @@ export class ServerCheckGuard implements CanActivateChild {
|
|||||||
* operation, the cached version is used.
|
* operation, the cached version is used.
|
||||||
*/
|
*/
|
||||||
listenForRouteChanges(): void {
|
listenForRouteChanges(): void {
|
||||||
|
// we'll always be too late for the first NavigationStart event with the router subscribe below,
|
||||||
|
// so this statement is for the very first route operation
|
||||||
|
this.rootDataService.invalidateRootCache();
|
||||||
|
|
||||||
this.router.events.pipe(
|
this.router.events.pipe(
|
||||||
filter(event => event instanceof NavigationStart),
|
filter(event => event instanceof NavigationStart),
|
||||||
).subscribe(() => {
|
).subscribe(() => {
|
||||||
|
Reference in New Issue
Block a user