-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d98a1a
commit 3e05ba8
Showing
13 changed files
with
901 additions
and
1,222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,53 @@ | ||
/** | ||
* Create the store with dynamic reducers | ||
*/ | ||
|
||
import { createStore, applyMiddleware } from 'redux'; | ||
import { composeWithDevTools } from 'redux-devtools-extension'; | ||
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'; | ||
import { createInjectorsEnhancer } from 'redux-injectors' | ||
import { createPhoenixChannelMiddleware } from '@trixta/phoenix-to-redux'; | ||
import Reactotron from './ReactotronConfig'; | ||
import createSagaMiddleware from 'redux-saga'; | ||
import createReducer from './reducers'; | ||
const phoenixChannelMiddleWare = createPhoenixChannelMiddleware(); | ||
|
||
export default function configureStore(initialState = {}, rootSaga) { | ||
let composeEnhancers = composeWithDevTools; | ||
export function configureAppStore(initialState = {}) { | ||
// 1. Reactotron sagaMonitor | ||
const sagaMonitor = Reactotron.createSagaMonitor(); | ||
const reduxSagaMonitorOptions = __DEV__ ? { sagaMonitor } : {}; | ||
|
||
const phoenixChannelMiddleWare = createPhoenixChannelMiddleware(); | ||
const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions); | ||
|
||
const { run: runSaga } = sagaMiddleware; | ||
// Create the store with two middleWares | ||
// 1. sagaMiddleware: Makes redux-sagas work | ||
// 2. phoenixChannelMiddleWare: integrates phoenix channels with redux | ||
const middleWares = [sagaMiddleware, phoenixChannelMiddleWare]; | ||
const middlewares = [phoenixChannelMiddleWare, sagaMiddleware]; | ||
|
||
const enhancers = [applyMiddleware(...middleWares)]; | ||
const enhancers = [ | ||
createInjectorsEnhancer({ | ||
createReducer, | ||
runSaga, | ||
}), | ||
]; | ||
|
||
if (__DEV__) { | ||
enhancers.push(Reactotron.createEnhancer()); | ||
} | ||
const store = createStore(createReducer(), initialState, composeEnhancers(...enhancers)); | ||
// Extensions | ||
// Kick off the root saga | ||
sagaMiddleware.run(rootSaga); | ||
store.injectedReducers = {}; // Reducer registry | ||
store.injectedSagas = {}; // Saga registry | ||
|
||
//Make reducers hot reloadable, see http://mxs.is/googmo | ||
/* istanbul ignore next */ | ||
if (module.hot) { | ||
module.hot.accept('./reducers', () => { | ||
store.replaceReducer(createReducer(store.injectedReducers)); | ||
}); | ||
} | ||
const store = configureStore({ | ||
preloadedState: initialState, | ||
reducer: createReducer(), | ||
middleware: [ | ||
...getDefaultMiddleware({ | ||
thunk: false, | ||
immutableCheck: { | ||
ignore: ['socket', 'channel', 'trixta', 'phoenix', 'router'], | ||
}, | ||
serializableCheck: false, | ||
}), | ||
...middlewares, | ||
], | ||
devTools: process.env.NODE_ENV !== 'production', | ||
enhancers, | ||
}); | ||
|
||
return store; | ||
} | ||
|
||
const store = configureAppStore({}); | ||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.