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 React from 'react'
import ReactDOM from 'react-dom'
import store from './store/store.js'
import { Provider } from 'react-redux'
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles'
import DragAndDropProvider from './components/common/dnd/DragAndDropProvider.jsx'
......@@ -26,8 +27,7 @@ const theme = createMuiTheme({
})
const render = () => {
const App = require('./components/App.jsx').default
const store = require('./store/store.js').default
let App = require('./components/App.jsx').default
ReactDOM.render(
<Provider store={store}>
......@@ -44,10 +44,6 @@ const render = () => {
/* eslint-disable no-undef */
if (module.hot) {
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()
export const INIT = 'INIT'
export const CLEAR = 'CLEAR'
export const LOGIN = 'LOGIN'
export const LOGOUT = 'LOGOUT'
export const SEARCH = 'SEARCH'
......@@ -7,6 +8,7 @@ export const SEARCH_CHANGE = 'SEARCH_CHANGE'
export const ERROR_CHANGE = 'ERROR_CHANGE'
export const ROUTE_CHANGE = 'ROUTE_CHANGE'
export const SET_INITIALIZED = 'SET_INITIALIZED'
export const SET_LOADING = 'SET_LOADING'
export const SET_SEARCH = 'SET_SEARCH'
export const SET_SESSION = 'SET_SESSION'
......@@ -17,6 +19,10 @@ export const init = () => ({
type: INIT
})
export const clear = () => ({
type: CLEAR
})
export const login = (username, password) => ({
type: LOGIN,
payload: {
......@@ -65,6 +71,13 @@ export const routeChange = route => ({
}
})
export const setInitialized = initialized => ({
type: SET_INITIALIZED,
payload: {
initialized
}
})
export const setLoading = loading => ({
type: SET_LOADING,
payload: {
......
......@@ -5,12 +5,26 @@ import session from './session/session.js'
import route from './route/route.js'
export default function root(state = {}, action) {
if (action.type === actions.INIT) {
state = {}
if (action.type === actions.CLEAR) {
state = {
initialized: state.initialized
}
}
return combineReducers({
initialized,
ui,
session,
route
})(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'
export function isPageAction(page, action) {
return (
action.type === actions.INIT ||
action.type === actions.CLEAR ||
page === (action.payload && action.payload.page)
)
}
......
......@@ -17,14 +17,19 @@ export default function* appSaga() {
}
function* init() {
try {
yield put(actions.setLoading(true))
yield call([dto, dto.init])
yield call([facade, facade.init])
} catch (e) {
yield put(actions.setError(e))
} finally {
yield put(actions.setLoading(false))
let initialized = yield select(selectors.getInitialized)
if (!initialized) {
try {
yield put(actions.setLoading(true))
yield call([dto, dto.init])
yield call([facade, facade.init])
yield put(actions.setInitialized(true))
} catch (e) {
yield put(actions.setError(e))
} finally {
yield put(actions.setLoading(false))
}
}
}
......@@ -62,7 +67,7 @@ function* logout() {
try {
yield put(actions.setLoading(true))
yield putAndWait(actions.apiRequest({ method: 'logout' }))
yield put(actions.init())
yield put(actions.clear())
yield put(actions.routeChange('/'))
} catch (e) {
yield put(actions.setError(e))
......
import routes from '../../common/consts/routes.js'
export const getInitialized = state => {
return state.initialized
}
export const getLoading = state => {
return state.ui.loading
}
......
......@@ -8,7 +8,12 @@ import history from './history.js'
function createStoreWithMiddleware() {
const sagaMiddleware = createSagaMiddleware()
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(
rootReducer,
......@@ -23,5 +28,13 @@ function 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 default store
......@@ -38,9 +38,7 @@ module.exports = {
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
use: ['react-hot', 'babel-loader']
},
{
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