-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixes 0-index issue with link preloader as per #988 * Allowing for disabled sourcemaps * Fix bad logic * Adds redux example * Ignores children in prop type validation * Rolls back to older canary to alleviate 404 issues * Example title metadata * Separate createStore * First pass at wrapping server render body * Moves api implementation into gatsby-ssr.js * Updates metadata
- Loading branch information
1 parent
4645524
commit 8fdca0b
Showing
13 changed files
with
195 additions
and
0 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
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,5 @@ | ||
# Redux | ||
|
||
https://redux.gatsbyjs.org | ||
|
||
Gatsby example site that shows use of redux. |
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,17 @@ | ||
import React from 'react' | ||
import { BrowserRouter as Router } from 'react-router-dom' | ||
import { Provider } from 'react-redux' | ||
|
||
import createStore from './src/state/createStore' | ||
|
||
exports.replaceRouterComponent = ({ history }) => { | ||
const store = createStore() | ||
|
||
const ConnectedRouterWrapper = ({ children }) => ( | ||
<Provider store={store}> | ||
<Router history={history}>{children}</Router> | ||
</Provider> | ||
) | ||
|
||
return ConnectedRouterWrapper | ||
} |
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,5 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `Gatsby Redux`, | ||
}, | ||
} |
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,20 @@ | ||
import React from 'react' | ||
import { renderToString } from 'react-dom/server' | ||
import { Provider } from 'react-redux' | ||
|
||
import createStore from './src/state/createStore' | ||
|
||
exports.replaceServerBodyRender = ({ component: body }) => { | ||
|
||
const store = createStore() | ||
|
||
const ConnectedBody = () => ( | ||
<Provider store={store}> | ||
{body} | ||
</Provider> | ||
) | ||
|
||
return { | ||
body: renderToString(<ConnectedBody/>), | ||
} | ||
} |
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,25 @@ | ||
{ | ||
"name": "gatsby-example-redux", | ||
"private": true, | ||
"description": "Gatsby example site that shows use of redux.", | ||
"version": "1.0.0", | ||
"author": "Scotty Eckenthal <scott.eckenthal@gmail.com>", | ||
"dependencies": { | ||
"gatsby": "1.0.0-alpha15-alpha.330d917d", | ||
"gatsby-link": "1.0.0-alpha15-alpha.330d917d", | ||
"lodash": "^4.16.4", | ||
"react-redux": "5.0.5", | ||
"react-router-redux": "4.0.8", | ||
"redux": "3.6.0", | ||
"slash": "^1.0.0" | ||
}, | ||
"keywords": [ | ||
"gatsby" | ||
], | ||
"license": "MIT", | ||
"main": "n/a", | ||
"scripts": { | ||
"develop": "gatsby develop", | ||
"build": "gatsby build" | ||
} | ||
} |
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,33 @@ | ||
import React from "react" | ||
|
||
module.exports = React.createClass({ | ||
render() { | ||
return ( | ||
<html op="news" lang="en"> | ||
<head> | ||
{this.props.headComponents} | ||
|
||
<meta name="referrer" content="origin" /> | ||
<meta charSet="utf-8" /> | ||
<meta | ||
name="Gatsby example site showing use with redux" | ||
content="Gatsby example site showing use with redux" | ||
/> | ||
<meta httpEquiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0" | ||
/> | ||
<title>Gatsby - Redux</title> | ||
</head> | ||
<body> | ||
<div | ||
id="___gatsby" | ||
dangerouslySetInnerHTML={{ __html: this.props.body }} | ||
/> | ||
{this.props.postBodyComponents} | ||
</body> | ||
</html> | ||
) | ||
}, | ||
}) |
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,49 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import Link from 'gatsby-link' | ||
import { connect } from 'react-redux' | ||
|
||
const Counter = ({ count, increment }) => ( | ||
<div> | ||
<p>Count: {count}</p> | ||
<button onClick={increment}>Increment</button> | ||
</div> | ||
) | ||
|
||
Counter.propTypes = { | ||
count: PropTypes.number.isRequired, | ||
increment: PropTypes.func.isRequired, | ||
} | ||
|
||
const mapStateToProps = ({ count }) => { | ||
return { count } | ||
} | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return { increment: () => dispatch({ type: `INCREMENT` }) } | ||
} | ||
|
||
const ConnectedCounter = connect(mapStateToProps, mapDispatchToProps)(Counter) | ||
|
||
class DefaultLayout extends React.Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Link to="/"> | ||
<h3> | ||
Redux example | ||
</h3> | ||
</Link> | ||
<ConnectedCounter/> | ||
<ul> | ||
<li><Link to="/a/">a</Link></li> | ||
<li><Link to="/b/">b</Link></li> | ||
<li><Link to="/c/">c</Link></li> | ||
</ul> | ||
{this.props.children()} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default DefaultLayout |
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,5 @@ | ||
import React from "react" | ||
|
||
const A = () => <p>A</p> | ||
|
||
export default A |
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,5 @@ | ||
import React from "react" | ||
|
||
const B = () => <p>B</p> | ||
|
||
export default B |
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,5 @@ | ||
import React from "react" | ||
|
||
const C = () => <p>C</p> | ||
|
||
export default C |
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,5 @@ | ||
import React from "react" | ||
|
||
const Home = () => <p>Home</p> | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createStore as reduxCreateStore } from 'redux' | ||
|
||
const reducer = (state, action) => { | ||
if (action.type === `INCREMENT`) { | ||
return Object.assign({}, state, { | ||
count: state.count + 1, | ||
}) | ||
} | ||
return state | ||
} | ||
|
||
const initialState = { count: 0 } | ||
|
||
const createStore = () => reduxCreateStore(reducer, initialState) | ||
export default createStore |