Created
February 5, 2020 12:11
-
-
Save gangstaJS/27b333c526cebc1abdb8b2edb1f16561 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import {applyMiddleware, compose, createStore} from 'redux'; | |
import {routerMiddleware} from 'react-router-redux'; | |
import thunk from 'redux-thunk'; | |
import {createBrowserHistory} from 'history'; | |
import rootReducer from './reducers'; | |
export const history = createBrowserHistory({ | |
basename: '/app', | |
}); | |
window.currntDataTrack = null; | |
document.addEventListener('click', (el) => { | |
const trackEl = el.target.closest('[data-track]'); | |
if(trackEl) { | |
window.currntDataTrack = trackEl.getAttribute('data-track'); | |
} else { | |
window.currntDataTrack = null; | |
} | |
}); | |
function track() { | |
return ({ dispatch, getState }) => next => { | |
let prevTitle = null; | |
return action => { | |
if(window.currntDataTrack !== prevTitle) { | |
console.log('%c['+window.currntDataTrack + '] '+ action.type, 'font-size: 20px; color: green; font-weight: bold'); | |
prevTitle = window.currntDataTrack; | |
} | |
return next(action); | |
}; | |
} | |
} | |
const initialState = {}; | |
const enhancers = []; | |
const middleware = [thunk, routerMiddleware(history), track()]; | |
if (process.env.NODE_ENV === 'development') { | |
const devToolsExtension = window.__REDUX_DEVTOOLS_EXTENSION__; | |
if (typeof devToolsExtension === 'function') { | |
enhancers.push(devToolsExtension()); | |
} | |
} | |
const composedEnhancers = compose(applyMiddleware(...middleware), ...enhancers); | |
const store = createStore(rootReducer, initialState, composedEnhancers); | |
if (module.hot) { | |
module.hot.accept('./reducers', () => { | |
const nextRootReducer = require('./reducers').default; | |
store.replaceReducer(nextRootReducer); | |
}); | |
} | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment