import React from 'react' ; import { AppConfigType } from '../types' ; import FSNetwork from '@brandingbrand/fsnetwork' ; import configureStore from '../store/configureStore' ; import { Store } from 'redux' ; import type { Request } from 'express' ; import AppRouter from '../lib/app-router' ; export interface WebApplication { element : JSX . Element ; getStyleElement : ( props ? : Partial < React . StyleHTMLAttributes < HTMLStyleElement > > ) => JSX . Element ; } export abstract class FSAppBase { appConfig : AppConfigType ; api : FSNetwork ; store ? : Store ; appRouter : AppRouter ; constructor ( appConfig ) { this . appConfig = appConfig ; this . api = new FSNetwork ( appConfig . remote || { } ) ; this . appRouter = new AppRouter ( appConfig ) ; } updatedInitialState = async ( excludeUncached ? , req ? ) => { let updatedState = this . appConfig . initialState || { } ; if ( this . appConfig . cachedData ) { updatedState = ( await this . appConfig . cachedData ( { initialState : updatedState , variables : { } } , req ) ) . initialState ; } if ( this . appConfig . uncachedData && excludeUncached !== false ) { updatedState = ( await this . appConfig . uncachedData ( { initialState : updatedState , variables : { } } , req ) ) . initialState ; } return updatedState ; } ; initApp = async ( ) => { if ( ! this . appConfig . serverSide ) { this . store = await this . getReduxStore ( await this . updatedInitialState ( ) ) ; } if ( this . appConfig . routerConfig ) { await this . appRouter . loadRoutes ( ) ; } this . registerScreens ( ) ; } ; getReduxStore = async ( initialState ? ) => { return configureStore ( initialState || this . appConfig . initialState , this . appConfig . reducers , this . appConfig . storeMiddleware || [ ] ) ; } ; abstract getApp ( appConfig ? , store ? ) ; abstract registerScreens ( ) ; abstract shouldShowDevMenu ( ) ; abstract startApp ( ) ; }