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-20 19:02:49 +03:00
|
|
|
import { Redoc, RedocProps } from '../../src/components/Redoc/Redoc';
|
2017-11-19 23:11:40 +03:00
|
|
|
import { AppStore } from '../../src/services/AppStore';
|
2017-11-21 14:00:33 +03:00
|
|
|
import { RedocRawOptions } from '../../src/services/RedocNormalizedOptions';
|
2018-01-22 21:30:53 +03:00
|
|
|
import { loadAndBundleSpec } from '../../src/utils/loadAndBundleSpec';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2018-03-17 15:17:09 +03:00
|
|
|
const renderRoot = (props: RedocProps) =>
|
2017-10-12 00:01:37 +03:00
|
|
|
render(
|
2018-03-17 15:17:09 +03:00
|
|
|
<AppContainer>
|
|
|
|
<Redoc {...props} />
|
|
|
|
</AppContainer>,
|
2017-10-12 00:01:37 +03:00
|
|
|
document.getElementById('example'),
|
|
|
|
);
|
|
|
|
|
|
|
|
const big = window.location.search.indexOf('big') > -1;
|
2018-01-22 21:30:53 +03:00
|
|
|
const swagger = window.location.search.indexOf('swagger') > -1; // compatibility mode ?
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2017-11-20 13:44:55 +03:00
|
|
|
const specUrl = swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml';
|
2017-11-14 18:46:50 +03:00
|
|
|
|
|
|
|
let store;
|
2018-02-08 19:41:02 +03:00
|
|
|
const options: RedocRawOptions = { nativeScrollbars: false };
|
2017-11-14 18:46:50 +03:00
|
|
|
|
|
|
|
async function init() {
|
2017-11-19 13:51:59 +03:00
|
|
|
const spec = await loadAndBundleSpec(specUrl);
|
2017-11-21 14:00:33 +03:00
|
|
|
store = new AppStore(spec, specUrl, options);
|
2018-03-17 15:17:09 +03:00
|
|
|
renderRoot({ store });
|
2017-11-14 18:46:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
init();
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
if (module.hot) {
|
2018-03-06 14:10:08 +03:00
|
|
|
const reload = (reloadStore = false) => async () => {
|
2017-10-12 00:01:37 +03:00
|
|
|
if (reloadStore) {
|
|
|
|
// create a new Store
|
2017-11-14 18:46:50 +03:00
|
|
|
store.dispose();
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2018-03-06 14:10:08 +03:00
|
|
|
const state = await store.toJS();
|
2017-11-14 18:46:50 +03:00
|
|
|
store = AppStore.fromJS(state);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
2018-03-17 15:17:09 +03:00
|
|
|
renderRoot({ store });
|
2017-10-12 00:01:37 +03:00
|
|
|
};
|
|
|
|
|
2017-11-19 23:11:40 +03:00
|
|
|
module.hot.accept(['../../src/components/Redoc/Redoc'], reload());
|
|
|
|
module.hot.accept(['../../src/services/AppStore'], reload(true));
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|