Fix React hot module reloading

master
Drew DeVault 2017-12-30 10:31:34 -05:00
parent ac4d290a28
commit e303f37572
1 changed files with 27 additions and 10 deletions

View File

@ -16,7 +16,13 @@ import Nav from './ui/navigation';
import Main from './ui/main';
import Connection from './ui/connection';
let skip_init = false;
export function initialize(uri) {
if (skip_init) {
skip_init = false;
return;
}
store.dispatch(socket_uri(uri));
store.dispatch(socket_update(SOCKET_STATE.CONNECTING));
ws_init(uri, () => {
@ -29,17 +35,28 @@ export function initialize(uri) {
});
}
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<Nav />
<div className="container-fluid">
<Main />
const render = main =>
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<Nav />
<div className="container-fluid">
{main}
</div>
</div>
</div>
</ConnectedRouter>
</Provider>, document.getElementById('root'));
</ConnectedRouter>
</Provider>, document.getElementById('root'));
render(<Main />);
if (module.hot) {
module.hot.accept('./ui/main.js', () => {
const NextMain = require('./ui/main.js').default;
skip_init = true;
render(<NextMain />, document.getElementById('react-root'));
});
}
navigator.registerProtocolHandler("magnet",
window.location.origin + "/add-torrent/%s",