Skip to content
Snippets Groups Projects
Commit d8f33963 authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

Make hot reloading work

parent 593628f3
No related branches found
No related tags found
No related merge requests found
import 'regenerator-runtime/runtime' import 'regenerator-runtime/runtime'
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import store from './store/store.js'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles' import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles'
import DragAndDropProvider from './components/common/dnd/DragAndDropProvider.jsx' import DragAndDropProvider from './components/common/dnd/DragAndDropProvider.jsx'
...@@ -26,8 +27,7 @@ const theme = createMuiTheme({ ...@@ -26,8 +27,7 @@ const theme = createMuiTheme({
}) })
const render = () => { const render = () => {
const App = require('./components/App.jsx').default let App = require('./components/App.jsx').default
const store = require('./store/store.js').default
ReactDOM.render( ReactDOM.render(
<Provider store={store}> <Provider store={store}>
...@@ -44,10 +44,6 @@ const render = () => { ...@@ -44,10 +44,6 @@ const render = () => {
/* eslint-disable no-undef */ /* eslint-disable no-undef */
if (module.hot) { if (module.hot) {
module.hot.accept('./components/App.jsx', () => setTimeout(render)) module.hot.accept('./components/App.jsx', () => setTimeout(render))
module.hot.accept('./store/reducers/reducers.js', () => {
const nextRootReducer = require('./store/reducers/reducers.js').default
store.replaceReducer(nextRootReducer)
})
} }
render() render()
export const INIT = 'INIT' export const INIT = 'INIT'
export const CLEAR = 'CLEAR'
export const LOGIN = 'LOGIN' export const LOGIN = 'LOGIN'
export const LOGOUT = 'LOGOUT' export const LOGOUT = 'LOGOUT'
export const SEARCH = 'SEARCH' export const SEARCH = 'SEARCH'
...@@ -7,6 +8,7 @@ export const SEARCH_CHANGE = 'SEARCH_CHANGE' ...@@ -7,6 +8,7 @@ export const SEARCH_CHANGE = 'SEARCH_CHANGE'
export const ERROR_CHANGE = 'ERROR_CHANGE' export const ERROR_CHANGE = 'ERROR_CHANGE'
export const ROUTE_CHANGE = 'ROUTE_CHANGE' export const ROUTE_CHANGE = 'ROUTE_CHANGE'
export const SET_INITIALIZED = 'SET_INITIALIZED'
export const SET_LOADING = 'SET_LOADING' export const SET_LOADING = 'SET_LOADING'
export const SET_SEARCH = 'SET_SEARCH' export const SET_SEARCH = 'SET_SEARCH'
export const SET_SESSION = 'SET_SESSION' export const SET_SESSION = 'SET_SESSION'
...@@ -17,6 +19,10 @@ export const init = () => ({ ...@@ -17,6 +19,10 @@ export const init = () => ({
type: INIT type: INIT
}) })
export const clear = () => ({
type: CLEAR
})
export const login = (username, password) => ({ export const login = (username, password) => ({
type: LOGIN, type: LOGIN,
payload: { payload: {
...@@ -65,6 +71,13 @@ export const routeChange = route => ({ ...@@ -65,6 +71,13 @@ export const routeChange = route => ({
} }
}) })
export const setInitialized = initialized => ({
type: SET_INITIALIZED,
payload: {
initialized
}
})
export const setLoading = loading => ({ export const setLoading = loading => ({
type: SET_LOADING, type: SET_LOADING,
payload: { payload: {
......
...@@ -5,12 +5,26 @@ import session from './session/session.js' ...@@ -5,12 +5,26 @@ import session from './session/session.js'
import route from './route/route.js' import route from './route/route.js'
export default function root(state = {}, action) { export default function root(state = {}, action) {
if (action.type === actions.INIT) { if (action.type === actions.CLEAR) {
state = {} state = {
initialized: state.initialized
}
} }
return combineReducers({ return combineReducers({
initialized,
ui, ui,
session, session,
route route
})(state, action) })(state, action)
} }
function initialized(state = false, action) {
switch (action.type) {
case actions.SET_INITIALIZED: {
return action.payload.initialized
}
default: {
return state
}
}
}
...@@ -6,6 +6,7 @@ export * from './browser.js' ...@@ -6,6 +6,7 @@ export * from './browser.js'
export function isPageAction(page, action) { export function isPageAction(page, action) {
return ( return (
action.type === actions.INIT || action.type === actions.INIT ||
action.type === actions.CLEAR ||
page === (action.payload && action.payload.page) page === (action.payload && action.payload.page)
) )
} }
......
...@@ -17,14 +17,19 @@ export default function* appSaga() { ...@@ -17,14 +17,19 @@ export default function* appSaga() {
} }
function* init() { function* init() {
try { let initialized = yield select(selectors.getInitialized)
yield put(actions.setLoading(true))
yield call([dto, dto.init]) if (!initialized) {
yield call([facade, facade.init]) try {
} catch (e) { yield put(actions.setLoading(true))
yield put(actions.setError(e)) yield call([dto, dto.init])
} finally { yield call([facade, facade.init])
yield put(actions.setLoading(false)) yield put(actions.setInitialized(true))
} catch (e) {
yield put(actions.setError(e))
} finally {
yield put(actions.setLoading(false))
}
} }
} }
...@@ -62,7 +67,7 @@ function* logout() { ...@@ -62,7 +67,7 @@ function* logout() {
try { try {
yield put(actions.setLoading(true)) yield put(actions.setLoading(true))
yield putAndWait(actions.apiRequest({ method: 'logout' })) yield putAndWait(actions.apiRequest({ method: 'logout' }))
yield put(actions.init()) yield put(actions.clear())
yield put(actions.routeChange('/')) yield put(actions.routeChange('/'))
} catch (e) { } catch (e) {
yield put(actions.setError(e)) yield put(actions.setError(e))
......
import routes from '../../common/consts/routes.js' import routes from '../../common/consts/routes.js'
export const getInitialized = state => {
return state.initialized
}
export const getLoading = state => { export const getLoading = state => {
return state.ui.loading return state.ui.loading
} }
......
...@@ -8,7 +8,12 @@ import history from './history.js' ...@@ -8,7 +8,12 @@ import history from './history.js'
function createStoreWithMiddleware() { function createStoreWithMiddleware() {
const sagaMiddleware = createSagaMiddleware() const sagaMiddleware = createSagaMiddleware()
const composeEnhancers = const composeEnhancers =
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
trace: true,
traceLimit: 25
})) ||
compose
let store = createStore( let store = createStore(
rootReducer, rootReducer,
...@@ -23,5 +28,13 @@ function createStoreWithMiddleware() { ...@@ -23,5 +28,13 @@ function createStoreWithMiddleware() {
let store = createStoreWithMiddleware() let store = createStoreWithMiddleware()
/* eslint-disable no-undef */
if (module.hot) {
module.hot.accept('./reducers/reducers.js', () => {
const nextRootReducer = require('./reducers/reducers.js').default
store.replaceReducer(nextRootReducer)
})
}
export { createStoreWithMiddleware as createStore } export { createStoreWithMiddleware as createStore }
export default store export default store
...@@ -38,9 +38,7 @@ module.exports = { ...@@ -38,9 +38,7 @@ module.exports = {
{ {
test: /\.(js|jsx)$/, test: /\.(js|jsx)$/,
exclude: /node_modules/, exclude: /node_modules/,
use: { use: ['react-hot', 'babel-loader']
loader: 'babel-loader'
}
}, },
{ {
test: /\.(css)$/, test: /\.(css)$/,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment