insomnia/app/ui/index.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

import * as React from 'react';
import ReactDOM from 'react-dom';
import {AppContainer} from 'react-hot-loader';
import {Provider} from 'react-redux';
import {DragDropContext} from 'react-dnd';
import App from './containers/app';
2017-08-23 03:33:07 +00:00
import * as models from '../models';
import * as db from '../common/database';
2017-08-23 03:33:07 +00:00
import {types as modelTypes} from '../models';
import {init as initStore} from './redux/modules';
import {init as initDB} from '../common/database';
import {init as initSync} from '../sync';
import {init as initAnalytics} from '../analytics';
import {init as initPlugins} from '../plugins';
2016-11-30 03:55:27 +00:00
import {getAccountId} from '../sync/session';
import DNDBackend from './dnd-backend';
import './css/index.less';
2017-08-23 03:33:07 +00:00
import {isDevelopment} from '../common/constants';
2016-03-16 05:49:42 +00:00
(async function () {
2016-11-30 03:55:27 +00:00
await initDB(modelTypes());
await initAnalytics(getAccountId());
// Create Redux store
const store = await initStore();
const context = DragDropContext(DNDBackend);
const DndComponent = context(App);
const render = Component => {
ReactDOM.render(
<AppContainer>
<Provider store={store}>
<Component/>
</Provider>
</AppContainer>,
document.getElementById('root')
);
};
render(DndComponent);
// Hot Module Replacement API
if (module.hot) {
module.hot.accept('./containers/app', () => {
render(DndComponent);
});
}
2016-11-30 03:55:27 +00:00
// Do things that can wait
process.nextTick(initSync);
2017-09-17 14:04:46 +00:00
process.nextTick(initPlugins);
})();
2017-08-23 03:33:07 +00:00
// Export some useful things for dev
if (isDevelopment()) {
window.models = models;
window.db = db;
2017-08-23 03:33:07 +00:00
}