-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,476 additions
and
125 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"printWidth": 80, | ||
"bracketSpacing": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"semi": true, | ||
"arrowParens": "avoid", | ||
"jsxBracketSameLine": true | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React from 'react' | ||
import React from 'react'; | ||
|
||
const About = () => ( | ||
<div> | ||
<h1>About Page</h1> | ||
<p>Did you get here via Redux?</p> | ||
</div> | ||
) | ||
); | ||
|
||
export default About | ||
export default About; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,61 @@ | ||
import React from 'react' | ||
import { push } from 'react-router-redux' | ||
import { bindActionCreators } from 'redux' | ||
import { connect } from 'react-redux' | ||
import React from 'react'; | ||
import { push } from 'react-router-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import { | ||
increment, | ||
incrementAsync, | ||
decrement, | ||
decrementAsync | ||
} from '../../modules/counter' | ||
} from '../../modules/counter'; | ||
|
||
const Home = props => ( | ||
<div> | ||
<h1>Home</h1> | ||
<p>Count: {props.count}</p> | ||
|
||
<p> | ||
<button onClick={props.increment} disabled={props.isIncrementing}>Increment</button> | ||
<button onClick={props.incrementAsync} disabled={props.isIncrementing}>Increment Async</button> | ||
<button onClick={props.increment} disabled={props.isIncrementing}> | ||
Increment | ||
</button> | ||
<button onClick={props.incrementAsync} disabled={props.isIncrementing}> | ||
Increment Async | ||
</button> | ||
</p> | ||
|
||
<p> | ||
<button onClick={props.decrement} disabled={props.isDecrementing}>Decrement</button> | ||
<button onClick={props.decrementAsync} disabled={props.isDecrementing}>Decrement Async</button> | ||
<button onClick={props.decrement} disabled={props.isDecrementing}> | ||
Decrement | ||
</button> | ||
<button onClick={props.decrementAsync} disabled={props.isDecrementing}> | ||
Decrement Async | ||
</button> | ||
</p> | ||
|
||
<p><button onClick={() => props.changePage()}>Go to about page via redux</button></p> | ||
<p> | ||
<button onClick={() => props.changePage()}> | ||
Go to about page via redux | ||
</button> | ||
</p> | ||
</div> | ||
) | ||
); | ||
|
||
const mapStateToProps = state => ({ | ||
count: state.counter.count, | ||
isIncrementing: state.counter.isIncrementing, | ||
isDecrementing: state.counter.isDecrementing | ||
}) | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => bindActionCreators({ | ||
increment, | ||
incrementAsync, | ||
decrement, | ||
decrementAsync, | ||
changePage: () => push('/about-us') | ||
}, dispatch) | ||
const mapDispatchToProps = dispatch => | ||
bindActionCreators( | ||
{ | ||
increment, | ||
incrementAsync, | ||
decrement, | ||
decrementAsync, | ||
changePage: () => push('/about-us') | ||
}, | ||
dispatch | ||
); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(Home) | ||
export default connect(mapStateToProps, mapDispatchToProps)(Home); |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,95 @@ | ||
export const INCREMENT_REQUESTED = 'counter/INCREMENT_REQUESTED' | ||
export const INCREMENT = 'counter/INCREMENT' | ||
export const DECREMENT_REQUESTED = 'counter/DECREMENT_REQUESTED' | ||
export const DECREMENT = 'counter/DECREMENT' | ||
export const INCREMENT_REQUESTED = 'counter/INCREMENT_REQUESTED'; | ||
export const INCREMENT = 'counter/INCREMENT'; | ||
export const DECREMENT_REQUESTED = 'counter/DECREMENT_REQUESTED'; | ||
export const DECREMENT = 'counter/DECREMENT'; | ||
|
||
const initialState = { | ||
count: 0, | ||
isIncrementing: false, | ||
isDecrementing: false | ||
} | ||
}; | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case INCREMENT_REQUESTED: | ||
return { | ||
...state, | ||
isIncrementing: true | ||
} | ||
}; | ||
|
||
case INCREMENT: | ||
return { | ||
...state, | ||
count: state.count + 1, | ||
isIncrementing: !state.isIncrementing | ||
} | ||
}; | ||
|
||
case DECREMENT_REQUESTED: | ||
return { | ||
...state, | ||
isDecrementing: true | ||
} | ||
}; | ||
|
||
case DECREMENT: | ||
return { | ||
...state, | ||
count: state.count - 1, | ||
isDecrementing: !state.isDecrementing | ||
} | ||
}; | ||
|
||
default: | ||
return state | ||
return state; | ||
} | ||
} | ||
}; | ||
|
||
export const increment = () => { | ||
return dispatch => { | ||
dispatch({ | ||
type: INCREMENT_REQUESTED | ||
}) | ||
}); | ||
|
||
dispatch({ | ||
type: INCREMENT | ||
}) | ||
} | ||
} | ||
}); | ||
}; | ||
}; | ||
|
||
export const incrementAsync = () => { | ||
return dispatch => { | ||
dispatch({ | ||
type: INCREMENT_REQUESTED | ||
}) | ||
}); | ||
|
||
return setTimeout(() => { | ||
dispatch({ | ||
type: INCREMENT | ||
}) | ||
}, 3000) | ||
} | ||
} | ||
}); | ||
}, 3000); | ||
}; | ||
}; | ||
|
||
export const decrement = () => { | ||
return dispatch => { | ||
dispatch({ | ||
type: DECREMENT_REQUESTED | ||
}) | ||
}); | ||
|
||
dispatch({ | ||
type: DECREMENT | ||
}) | ||
} | ||
} | ||
}); | ||
}; | ||
}; | ||
|
||
export const decrementAsync = () => { | ||
return dispatch => { | ||
dispatch({ | ||
type: DECREMENT_REQUESTED | ||
}) | ||
}); | ||
|
||
return setTimeout(() => { | ||
dispatch({ | ||
type: DECREMENT | ||
}) | ||
}, 3000) | ||
} | ||
} | ||
}); | ||
}, 3000); | ||
}; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { combineReducers } from 'redux' | ||
import { routerReducer } from 'react-router-redux' | ||
import counter from './counter' | ||
import { combineReducers } from 'redux'; | ||
import { routerReducer } from 'react-router-redux'; | ||
import counter from './counter'; | ||
|
||
export default combineReducers({ | ||
router: routerReducer, | ||
counter | ||
}) | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,23 @@ | ||
import { createStore, applyMiddleware, compose } from 'redux' | ||
import { routerMiddleware } from 'react-router-redux' | ||
import thunk from 'redux-thunk' | ||
import createHistory from 'history/createBrowserHistory' | ||
import rootReducer from './modules' | ||
import { createStore, applyMiddleware, compose } from 'redux'; | ||
import { routerMiddleware } from 'react-router-redux'; | ||
import thunk from 'redux-thunk'; | ||
import createHistory from 'history/createBrowserHistory'; | ||
import rootReducer from './modules'; | ||
|
||
export const history = createHistory() | ||
export const history = createHistory(); | ||
|
||
const initialState = {} | ||
const enhancers = [] | ||
const middleware = [ | ||
thunk, | ||
routerMiddleware(history) | ||
] | ||
const initialState = {}; | ||
const enhancers = []; | ||
const middleware = [thunk, routerMiddleware(history)]; | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
const devToolsExtension = window.devToolsExtension | ||
const devToolsExtension = window.devToolsExtension; | ||
|
||
if (typeof devToolsExtension === 'function') { | ||
enhancers.push(devToolsExtension()) | ||
enhancers.push(devToolsExtension()); | ||
} | ||
} | ||
|
||
const composedEnhancers = compose( | ||
applyMiddleware(...middleware), | ||
...enhancers | ||
) | ||
const composedEnhancers = compose(applyMiddleware(...middleware), ...enhancers); | ||
|
||
export default createStore( | ||
rootReducer, | ||
initialState, | ||
composedEnhancers | ||
) | ||
export default createStore(rootReducer, initialState, composedEnhancers); |
Oops, something went wrong.