From c30aaf93187d9a215ffc5c536855b7cc4b64e9de Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Tue, 16 Feb 2021 13:55:53 +0100
Subject: [PATCH] move all atlas ready from route to const

---
 src/routerModule/router.service.spec.ts | 21 +--------------
 src/routerModule/router.service.ts      | 35 +++++--------------------
 2 files changed, 7 insertions(+), 49 deletions(-)

diff --git a/src/routerModule/router.service.spec.ts b/src/routerModule/router.service.spec.ts
index f389f56d2..6a6b198a4 100644
--- a/src/routerModule/router.service.spec.ts
+++ b/src/routerModule/router.service.spec.ts
@@ -3,17 +3,14 @@ import { discardPeriodicTasks, fakeAsync, TestBed, tick } from "@angular/core/te
 import { Router } from "@angular/router"
 import { RouterTestingModule } from '@angular/router/testing'
 import { MockStore, provideMockStore } from "@ngrx/store/testing"
-import { hot } from "jasmine-marbles"
 import { of } from "rxjs"
-import { viewerStateFetchedAtlasesSelector, viewerStateFetchedTemplatesSelector } from "src/services/state/viewerState/selectors"
 import { PureContantService } from "src/util"
 import { RouterService } from "./router.service"
 import * as util from './util'
 
 const { routes, DummyCmp } = util
 const dummyPureConstantService = {
-  getTemplateEndpoint$: of(['dummy']),
-  totalAtlasesLength: 2
+  allFetchingReady$: of(true)
 }
 
 let cvtStateToHashedRoutesSpy: jasmine.Spy 
@@ -51,28 +48,12 @@ describe('> router.service.ts', () => {
           }
         ]
       })
-
-      const mockStore = TestBed.inject(MockStore)
-      mockStore.overrideSelector(viewerStateFetchedTemplatesSelector, ['dummy'])
-      mockStore.overrideSelector(viewerStateFetchedAtlasesSelector, ['foo', 'bar'])
     })
 
     afterEach(() => {
       cvtStateToHashedRoutesSpy.calls.reset()
       cvtFullRouteToStateSpy.calls.reset()
     })
-    it('> can be init, and configuration emits allFetchingReady$', () => {
-      const service = TestBed.inject(RouterService)
-      expect(service).toBeTruthy()
-      expect(
-        service['allFetchingReady$']
-      ).toBeObservable(
-        hot('(a|)', {
-          a: true
-        })
-      )
-    })
-
     describe('> on state set', () => {
 
       it('> should call cvtStateToHashedRoutes', fakeAsync(() => {
diff --git a/src/routerModule/router.service.ts b/src/routerModule/router.service.ts
index b4084a922..9f3871aab 100644
--- a/src/routerModule/router.service.ts
+++ b/src/routerModule/router.service.ts
@@ -2,11 +2,8 @@ import { Injectable } from "@angular/core";
 import { APP_BASE_HREF } from "@angular/common";
 import { Inject } from "@angular/core";
 import { NavigationEnd, Router } from '@angular/router'
-import { select, Store } from "@ngrx/store";
-import { combineLatest, Observable } from "rxjs";
-import { debounceTime, filter, map, mapTo, shareReplay, switchMapTo, take, withLatestFrom } from "rxjs/operators";
-import { viewerStateFetchedTemplatesSelector } from "src/services/state/viewerState.store.helper";
-import { viewerStateFetchedAtlasesSelector } from "src/services/state/viewerState/selectors";
+import { Store } from "@ngrx/store";
+import { debounceTime, filter, map, shareReplay, switchMapTo, take, withLatestFrom } from "rxjs/operators";
 import { generalApplyState } from "src/services/stateStore.helper";
 import { PureContantService } from "src/util";
 import { cvtStateToHashedRoutes, cvtFullRouteToState } from "./util";
@@ -17,8 +14,6 @@ import { cvtStateToHashedRoutes, cvtFullRouteToState } from "./util";
 
 export class RouterService {
 
-  private allFetchingReady$: Observable<boolean>
-
   private logError(...e: any[]) {
     console.log(...e)
   }
@@ -39,31 +34,13 @@ export class RouterService {
 
     navEnd$.subscribe()
 
-    this.allFetchingReady$ = combineLatest([
-      pureConstantService.getTemplateEndpoint$.pipe(
-        filter(arr => !!arr && Array.isArray(arr)),
-        map(arr => arr.length)
-      ),
-      store$.pipe(
-        select(viewerStateFetchedTemplatesSelector),
-        filter(arr => !!arr && Array.isArray(arr)),
-        map(arr => arr.length)
-      ),
-      store$.pipe(
-        select(viewerStateFetchedAtlasesSelector),
-        filter(arr => !!arr && Array.isArray(arr)),
-        map(arr => arr.length)
-      )
-    ]).pipe(
-      filter(([ expNumTmpl, actNumTmpl, actNumAtlas ]) => {
-        return expNumTmpl === actNumTmpl && actNumAtlas === pureConstantService.totalAtlasesLength
-      }),
-      mapTo(true),
+    const ready$ = pureConstantService.allFetchingReady$.pipe(
+      filter(flag => !!flag),
       take(1),
       shareReplay(1),
     )
 
-    this.allFetchingReady$.pipe(
+    ready$.pipe(
       switchMapTo(
         navEnd$.pipe(
           withLatestFrom(store$)
@@ -91,7 +68,7 @@ export class RouterService {
     // TODO this may still be a bit finiky. 
     // we rely on that update of store happens within 160ms
     // which may or many not be 
-    this.allFetchingReady$.pipe(
+    ready$.pipe(
       switchMapTo(
         store$.pipe(
           debounceTime(160),
-- 
GitLab