Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use simple-redux-router UPDATE_PATH action type to clear counter #12

Open
wants to merge 1 commit into
base: routed-email-app
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ import { DevTools, LogMonitor, DebugPanel } from 'redux-devtools/lib/react';
import App from './containers/App'
import configureStore, { USE_DEV_TOOLS } from './store/configureStore'
import { Route, Router as RealRouter } from 'react-router'

import { syncReduxAndRouter } from 'redux-simple-router'

import * as actions from './actions/';
import emailApp from './emailApp'

import Folders from './components/Folders'
import Folder from './components/Folder'
import Emails from './components/Emails'
import EmailPreview from './components/EmailPreview'
import Counter from './components/Counter'

import generatePageLoaders from './pageLoaders'

import createBrowserHistory from 'history/lib/createBrowserHistory'

class Router extends RealRouter {
render() {
console.log("Rendering Router")
Expand All @@ -28,11 +35,16 @@ class Router extends RealRouter {
}
}


window.emailApp = emailApp;
const store = configureStore();

const pageLoaders = generatePageLoaders(store.dispatch);

const history = createBrowserHistory();

syncReduxAndRouter(history, store)

const debugPanel = USE_DEV_TOOLS ? (
<DebugPanel top right bottom>
<DevTools store={store} monitor={LogMonitor} />
Expand All @@ -43,14 +55,14 @@ let rootElement = document.getElementById('root')
render(
<div>
<Provider store={store}>
<Router>
<Router history={history}>
<Route path="/" component={App} onEnter={pageLoaders.appShow}>
<Route path="folders" component={Folders} onEnter={pageLoaders.foldersIndex}/>
<Route path="emails" component={Emails} onEnter={pageLoaders.emailsIndex}/>
<Route path="folder/:folderId" component={Folder} onEnter={pageLoaders.folderShow}>
<Route path="email/:emailId" component={EmailPreview}/>
</Route>
<Route path="counter" component={Counter} onEnter={() => store.dispatch(actions.initializeCounter())}/>
<Route path="counter" component={Counter}/>
</Route>
</Router>
</Provider>
Expand Down
15 changes: 15 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"uid": ">=0.0.2",
"faker": ">=0.7.2",
"lodash": "^3.10.1",
"history": "^1.12.0",
"react-router": "^1.0.0"
"history": "^1.13.0",
"react-router": "^1.0.0",
"redux-simple-router": "^0.0.10"
},
"devDependencies": {
"babel-core": "^5.6.18",
Expand Down
6 changes: 5 additions & 1 deletion reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { combineReducers } from 'redux'
import emailApp from '../emailApp'
import { OPEN_EMAIL, REMOVED_EMAIL, INCREMENT_COUNTER, INITIALIZE_COUNTER } from '../actions';
import { FETCHED_EMAILS } from '../emailApp/actions/emailActions'
import { UPDATE_PATH, routeReducer } from 'redux-simple-router'

const openEmailsReducer = function(state = [], action) {
switch(action.type) {
Expand All @@ -16,7 +17,9 @@ const openEmailsReducer = function(state = [], action) {

const counterReducer = function(state = 0, action) {
switch(action.type) {
case INITIALIZE_COUNTER:
case UPDATE_PATH:
console.log("UPDATE_PATH");
console.log(action);
return 0;
case INCREMENT_COUNTER:
return state + 1;
Expand All @@ -33,6 +36,7 @@ const rootReducer = combineReducers({
counter: counterReducer,
emailApp: emailApp.reducer,
gui: guiReducer,
routing: routeReducer
});

export default rootReducer;