import { Stream } from 'xstream' ; import { Home } from './Home' ; import { Sources , Sinks } from 'components/App' ; import { Layout } from 'layouts' ; import switchPath from 'switch-path' ; import { Commits } from './Commits' ; export interface RouteComponent { ( sources ) : Partial < Sinks > ; } interface RouteResolution { path ? : string ; getComponent : ( ) => Promise < RouteComponent > ; getLayout ? : ( ) => Promise < Layout > ; sources ? : any ; } interface ParameterizedRouteResolution { ( a , b ? , c ? , d ? ) : RouteResolution ; } export interface RouteDefinitions { [ path ] : RouteResolution | ParameterizedRouteResolution | RouteDefinitions ; } const getHeaderLayout = async ( ) => { const { HeaderLayout } = await import ( 'layouts/HeaderLayout' ) ; return HeaderLayout ; } ; const getComponent = < T > ( component ) => async ( ) => await Promise . resolve ( component ) ; const routes = { '/' : { getComponent : getComponent ( Home ) , getLayout : getHeaderLayout } , '/about' : { getComponent : async ( ) => { const { About } = await import ( './About' ) ; return About ; } , getLayout : getHeaderLayout } , '/commits' : Commits } ; const resolveImplementation = < T > ( routes , route ) : RouteResolution => { const { path , value : { getComponent , getLayout , sources } } = switchPath ( route , routes ) ; return { path , getComponent , getLayout , sources } ; } ; export const resolve = ( route ) => resolveImplementation ( routes , route ) ;