mirror of
https://github.com/strapi/strapi.git
synced 2025-08-07 16:29:18 +00:00
Admin: Allow reducers to be injected async into the store
Co-authored-by: Josh Ellis <josh.ellis@strapi.io>
This commit is contained in:
parent
e66609ec27
commit
d252d9da2d
@ -1,5 +1,4 @@
|
||||
import { createStore, applyMiddleware, compose } from 'redux';
|
||||
import createReducer from './createReducer';
|
||||
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
|
||||
|
||||
const configureStore = (appMiddlewares, appReducers) => {
|
||||
let composeEnhancers = compose;
|
||||
@ -19,11 +18,30 @@ const configureStore = (appMiddlewares, appReducers) => {
|
||||
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({});
|
||||
}
|
||||
|
||||
return createStore(
|
||||
createReducer(appReducers),
|
||||
const store = createStore(
|
||||
createReducer(appReducers, {}),
|
||||
{},
|
||||
composeEnhancers(applyMiddleware(...middlewares))
|
||||
);
|
||||
|
||||
// Add a dictionary to keep track of the registered async reducers
|
||||
store.asyncReducers = {};
|
||||
|
||||
// Create an inject reducer function
|
||||
// This function adds the async reducer, and creates a new combined reducer
|
||||
store.injectReducer = (key, asyncReducer) => {
|
||||
store.asyncReducers[key] = asyncReducer;
|
||||
store.replaceReducer(createReducer(appReducers, store.asyncReducers));
|
||||
};
|
||||
|
||||
return store;
|
||||
};
|
||||
|
||||
const createReducer = (appReducers, asyncReducers) => {
|
||||
return combineReducers({
|
||||
...appReducers,
|
||||
...asyncReducers,
|
||||
});
|
||||
};
|
||||
|
||||
export default configureStore;
|
||||
|
@ -1,5 +0,0 @@
|
||||
import { combineReducers } from 'redux';
|
||||
|
||||
const createReducer = (reducers) => combineReducers(reducers);
|
||||
|
||||
export default createReducer;
|
Loading…
x
Reference in New Issue
Block a user