Skip to content

Commit c60353a

Browse files
committed
added redux devtools integration aka Time Travel Debugging
1 parent aa7baed commit c60353a

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/reducers/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import { routerReducer } from 'react-router-redux';
44
import currencyRatesReducer from './currency-rates-reducer';
55
import currencyConverterReducer from './currency-converter-reducer';
66

7-
export const initialState = {
8-
};
9-
10-
export const rootReducer = combineReducers({
7+
export const reducers = combineReducers({
118
routing: routerReducer,
129
currencyRates: currencyRatesReducer,
1310
currencyConverter: currencyConverterReducer
1411
});
15-
16-
export const hotReloadReducer = (state, action) => action.payload;

src/store.tsx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import { createStore } from 'redux';
2-
import { initialState, rootReducer } from './reducers/index';
2+
import { reducers } from './reducers/index';
3+
declare const window: any;
34

4-
export const store = createStore(rootReducer, initialState);
5+
const recoverState = () => ({});
6+
7+
export const store = createStore(
8+
reducers,
9+
recoverState(),
10+
window.devToolsExtension && window.devToolsExtension()
11+
);
512

613
// hot-reload hook, rehydrating the state of redux store
714
export function __reload(exports) {
815
console.log(exports.store.getState());
9-
// if (exports.store) {
10-
// const localStore = exports.store;
11-
// const prevState = localStore.getState();
12-
//
13-
// localStore.replaceReducer(hotReloadReducer);
14-
// localStore.dispatch({ type: null, payload: prevState });
15-
// // console.log('store rehydrated', localStore.getState());
16-
//
17-
// localStore.replaceReducer(rootReducer);
18-
// }
1916
}
17+
18+
// custom hot-reload using reducer replacement
19+
// const hotReloadReducer = (state, action) => action.payload;
20+
// if (exports.store) {
21+
// const localStore = exports.store;
22+
// const prevState = localStore.getState();
23+
//
24+
// localStore.replaceReducer(hotReloadReducer);
25+
// localStore.dispatch({ type: null, payload: prevState });
26+
// console.log('store rehydrated', localStore.getState());
27+
//
28+
// localStore.replaceReducer(rootReducer);

0 commit comments

Comments
 (0)