import * as React from 'react'; import * as ReactDOM from 'react-dom'; import { Provider, Store } from 'react-redux'; import { ConnectedRouter } from 'react-router-redux'; import createSagaMiddleware, { SagaMiddleware } from 'redux-saga'; import { History } from 'history'; import * as injectTapEventPlugin from 'react-tap-event-plugin'; import Platform from '@overflow/commons/platform'; import AppContext from '@overflow/commons/context'; import * as AppContextLifecycleActions from '@overflow/commons/context/redux/action/lifecycle'; import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC'; import { store, sagaMiddleware, history } from './redux/store'; import appConfig, { Config } from './config'; import sagas from './redux/saga'; // import routes from './router'; import App from './views/App'; injectTapEventPlugin(); const rpcURL = 'ws://127.0.0.1:18081/rpc'; class Application { private config: Config; private container: HTMLElement; private context: AppContext; private rpcClient: WebSocketRPC; private store: Store; private sagaMiddleware: SagaMiddleware; private history: History; public constructor() { this.config = appConfig; this.sagaMiddleware = sagaMiddleware; this.store = store; this.history = history; } public static async Run(): Promise { let application = new Application(); return application.start(); } private async start(): Promise { try { this.container = await Platform.getAppContainer(this.config.container.placeholderID); this.displayLoading(); this.context = await this.initContext(); // this.rpcClient = await this.initRpcClient(); await this.initSagaEffect(); this.store.dispatch(AppContextLifecycleActions.initialized()); this.displayApp(); } catch (e) { console.error(e); this.displayError(e); } } private initContext(): Promise { const appContext = new Promise(resolve => { const context = AppContext.getContext(); resolve(context); }); return appContext; } private initRpcClient(): Promise { const rpcClient = new Promise((resolve, reject) => { let client = new WebSocketRPC(this.config.rpc.url); client.initialize() .then(() => { resolve(client); }) .catch((err: any) => { reject(err); }); }); return rpcClient; } private initSagaEffect(): Promise { const rpcClient = new Promise(resolve => { this.sagaMiddleware.run(sagas); resolve(); }); return rpcClient; } private displayLoading(): void { ReactDOM.render(

Loading...

, this.container, ); } private displayError(e: Error): void { ReactDOM.render(

{e.message}

, this.container, ); } private displayApp(): void { ReactDOM.render( , this.container, ); } } Application.Run();