Skip to content
Snippets Groups Projects
Commit c30aaf93 authored by Xiao Gui's avatar Xiao Gui
Browse files

move all atlas ready from route to const

parent 962f682b
No related branches found
No related tags found
No related merge requests found
......@@ -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(() => {
......
......@@ -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),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment