import type { NavigationRoute } from '@tinkoff/router' ; import type { Provider } from '@tramvai/core' ; import { commandLineListTokens , provide } from '@tramvai/core' ; import { STORE_TOKEN , ACTION_PAGE_RUNNER_TOKEN , ACTION_REGISTRY_TOKEN , } from '@tramvai/tokens-common' ; import { ROUTER_TOKEN } from '@tramvai/tokens-router' ; import { RouterStore , setCurrentNavigation , setUrlOnRehydrate } from '../stores/RouterStore' ; import { providers as commonProviders } from './common' ; import { runActionsFactory } from './hooks/runActions' ; export const providers = [ ... commonProviders , provide ( { provide : commandLineListTokens . customerStart , multi : true , useFactory : ( { router , store } ) => { return function routerInit ( ) { return router . rehydrate ( { to : store . getState ( RouterStore ) . currentRoute as NavigationRoute , } ) ; } ; } , deps : { router : ROUTER_TOKEN , store : STORE_TOKEN , } , } ) , provide ( { provide : commandLineListTokens . clear , multi : true , useFactory : ( { router , store } ) => { return function routerStart ( ) { const routerState = store . getState ( ) . router ; if ( routerState . currentUrl . href !== window . location . href ) { store . dispatch ( setUrlOnRehydrate ( router . getCurrentUrl ( ) ) ) ; } return router . start ( ) ; } ; } , deps : { router : ROUTER_TOKEN , store : STORE_TOKEN , } , } ) , provide ( { provide : commandLineListTokens . clear , multi : true , useFactory : runActionsFactory , deps : { router : ROUTER_TOKEN , actionRegistry : ACTION_REGISTRY_TOKEN , actionPageRunner : ACTION_PAGE_RUNNER_TOKEN , } , } ) , ] ;