import * as Hydux from '../../../../../src/index' ; import withReact , { React } from 'hydux-react' ; import * as ReactDOM from 'react-dom/server' ; import withSSR from '../../../../../src/enhancers/ssr' ; import { ActionsType } from '../../../../../src/types' ; import withRouter , { mkLink , History , HashHistory , BrowserHistory , RouterActions , RouterState , Routes , MemoryHistory } from '../../../../../src/enhancers/router' ; import * as Counter from '../counter' ; import '../polyfill.ts' ; import * as State from './State' ; import * as View from './View' ; import * as Utils from '../utils' ; export function main ( path ? ) { const noop = < T > ( f ) => f ; let withEnhancers = Hydux . compose ( __is_browser ? noop : withSSR < State . State , State . Actions > ( { renderToString ( view ) { return ReactDOM . renderToString ( view ) ; } , } ) , withRouter < State . State , State . Actions > ( { history : __is_browser ? State . history : new MemoryHistory ( { initPath : path } ) , routes : State . routes , ssr : State . isSSR , isServer : ! __is_browser , } ) , __is_browser ? withReact < State . State , State . Actions > ( document . getElementById ( 'root' ) , { hydrate : true } ) as any as ( ( app : Hydux . App < State . State , State . Actions > ) => Hydux . App < State . State , State . Actions > ) : noop ) ; let app = withEnhancers ( Hydux . app ) ; if ( process . env . NODE_ENV === 'development' && __is_browser ) { const devTools = require ( 'hydux/lib/enhancers/devtools' ) . default ; const logger = require ( 'hydux/lib/enhancers/logger' ) . default ; const hmr = require ( 'hydux/lib/enhancers/hmr' ) . default ; app = logger ( ) ( app ) ; app = devTools ( ) ( app ) ; app = hmr ( ) ( app ) ; } const ctx = app ( { init : State . init , actions : State . actions , view : View . root , } ) ; if ( __dev ) { ( window as any ) . ctx = ctx ; } return ctx ; } if ( __is_browser ) { main ( ) ; }