2017-10-12 00:01:37 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
2017-11-14 18:46:50 +03:00
|
|
|
import { AppContainer } from 'react-hot-loader';
|
2017-10-12 00:01:37 +03:00
|
|
|
// import DevTools from 'mobx-react-devtools';
|
|
|
|
|
2017-11-14 18:46:50 +03:00
|
|
|
import { Redoc } from './components/Redoc/Redoc';
|
2017-10-12 00:01:37 +03:00
|
|
|
import { AppStore } from './services/AppStore';
|
2017-11-14 18:46:50 +03:00
|
|
|
import { loadSpec } from './utils/loadSpec';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2017-11-14 18:46:50 +03:00
|
|
|
const renderRoot = (Component: typeof Redoc, props: { store: AppStore }) =>
|
2017-10-12 00:01:37 +03:00
|
|
|
render(
|
|
|
|
<div>
|
|
|
|
<AppContainer>
|
|
|
|
<Component {...props} />
|
|
|
|
</AppContainer>
|
|
|
|
</div>,
|
|
|
|
document.getElementById('example'),
|
|
|
|
);
|
|
|
|
|
|
|
|
const big = window.location.search.indexOf('big') > -1;
|
|
|
|
|
2017-11-14 18:46:50 +03:00
|
|
|
const specUrl = big ? 'big-swagger.json' : 'swagger.yaml';
|
|
|
|
|
|
|
|
let store;
|
|
|
|
|
|
|
|
async function init() {
|
|
|
|
const spec = await loadSpec(specUrl);
|
|
|
|
store = new AppStore(spec, specUrl);
|
|
|
|
renderRoot(Redoc, { store: store });
|
|
|
|
}
|
|
|
|
|
|
|
|
init();
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
if (module.hot) {
|
|
|
|
const reload = (reloadStore = false) => () => {
|
|
|
|
if (reloadStore) {
|
|
|
|
// create a new Store
|
2017-11-14 18:46:50 +03:00
|
|
|
store.dispose();
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2017-11-14 18:46:50 +03:00
|
|
|
const state = store.toJS();
|
|
|
|
store = AppStore.fromJS(state);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
2017-11-14 18:46:50 +03:00
|
|
|
renderRoot(Redoc, { store: store });
|
2017-10-12 00:01:37 +03:00
|
|
|
};
|
|
|
|
|
2017-11-14 18:46:50 +03:00
|
|
|
module.hot.accept(['./components/Redoc/Redoc'], reload());
|
2017-10-12 00:01:37 +03:00
|
|
|
module.hot.accept(['./services/AppStore'], reload(true));
|
|
|
|
}
|