futurice / pepperoni-app-kit

Pepperoni - React Native App Starter Kit for Android and iOS
http://getpepperoni.com
MIT License
4.63k stars 646 forks source link

Missing redux hot reload snippet #90

Open fabriziomoscon opened 8 years ago

fabriziomoscon commented 8 years ago

It seems by the look of it that the code to make Hot Module Reload with redux is missing.

See examples here: https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/redux/create.js#L28-L32

and here: https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html#redux-stores

@jevakallio do you think this code in store.js will work?

import reducer from './reducer';
if (__DEV__ && module.hot) {
    module.hot.accept(() => {
        store.replaceReducer(reducer);
    });
}
jevakallio commented 8 years ago

In theory that should work, with the exception that we would need to require('./reducer') inside the accept callback, and modify the reducer.js file to return a function that creates the new reducer (as implemented in https://github.com/futurice/pepperoni-app-kit/commit/a6c3540be25df66049064f8f2c5052e5d84f84ea):

if (__DEV__ && module.hot) {
    module.hot.accept(() => {
        const createReducer = require('./reducer').default;
        store.replaceReducer(createReducer());
    });
}

However when I tried that now, I could not get it to work. The redux hot loading warning no longer shows, and I can also verify in the debugger that the new reducer function gets loaded, but the new reducer behaviour is not taken into use.

I think this is caused by the redux-loop store enhancer that effectively clones the store when it's taken into use, and the replaceReducer has no effect because it's modifying the original store instance, and not the cloned one.

This feature would be nifty, but I don't currently have time to dig deeper into this.

yinghang commented 8 years ago

+1

tino-junge commented 7 years ago

@fabriziomoscon did you find a way to get hot reloading in redux working ?

fabriziomoscon commented 7 years ago

@tino-junge I haven't managed to make it work. In my case that snippet generate an infinite loop which reaches Max call stack at some point. This happens every time I make a change to a *State.js file