Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { Provider } from 'react-redux'
  4. import { createStore, applyMiddleware } from 'redux'
  5. import rootReducer from './reducers'
  6. import App from './App';
  7. import * as serviceWorker from './serviceWorker';
  8. import { routerMiddleware, push } from 'connected-react-router'
  9. import { createBrowserHistory } from 'history'
  10. import createSagaMiddleware from 'redux-saga'
  11. import { getItemPath } from './util/path-utils'
  12.  
  13. import mySaga from './saga'
  14.  
  15. export const history = createBrowserHistory()
  16.  
  17. const middleware = store => next => action => {
  18. if (action.type === "ADD_ITEM") {
  19. const state = store.getState();
  20. store.dispatch(push(`${state.router.location.pathname}?${getItemPath([...state.items, action.data])}`));
  21. }
  22. next(action);
  23. }
  24.  
  25. const sagaMiddleware = createSagaMiddleware()
  26.  
  27. const store = createStore(rootReducer(history), applyMiddleware(sagaMiddleware, middleware, routerMiddleware(history)))
  28.  
  29. sagaMiddleware.run(mySaga)
  30.  
  31. store.dispatch({ type: "INIT_APP" })
  32.  
  33. ReactDOM.render(<Provider store={store}>
  34. <App />
  35. </Provider>, document.getElementById('root'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement