f8a2fa32 |
import {createActionDispatcher} from "./action-router";
function buildMiddleware(actionDispatcher) {
|
5c5f8ac3 |
return _ => next => action => {
|
fa8218e7 |
actionDispatcher.receiveAction(action);
|
77ace510 |
|
f8a2fa32 |
return next(action);
};
}
|
df6a63f6 |
function enhanceStoreFactory(actionDispatcher) {
|
f8a2fa32 |
return function enhanceStore(nextStoreCreator) {
const middleware = buildMiddleware(actionDispatcher);
return (reducer, finalInitialState, enhancer) => {
const theStore = nextStoreCreator(reducer, finalInitialState, enhancer);
|
77ace510 |
actionDispatcher.addActionListener((action) => theStore.dispatch(action));
|
f8a2fa32 |
|
df6a63f6 |
theStore.pathForAction = actionDispatcher.pathForAction.bind(actionDispatcher);
|
f8a2fa32 |
theStore.dispatch = middleware(theStore)(
theStore.dispatch.bind(theStore)
);
return theStore;
};
};
}
|
77ace510 |
export default function installBrowserRouter(routesConfig, _window = window) {
const actionDispatcher = createActionDispatcher(routesConfig, _window);
|
f8a2fa32 |
const middleware = x => {
//eslint-disable-next-line no-console
console.warn(
"Using the routedux middleware directly is deprecated, the enhancer now" +
" applies it automatically and the middleware is now a no-op that" +
" will be removed in later versions."
);
return y => y;
};
return {
middleware,
|
df6a63f6 |
enhancer: enhanceStoreFactory(actionDispatcher),
|
f8a2fa32 |
init: actionDispatcher.receiveLocation.bind(
actionDispatcher,
|
77ace510 |
_window.location
|
f8a2fa32 |
),
_actionDispatcher: actionDispatcher
};
}
|