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

[v2] Deprecate pathContext in favor of pageContext #3515

Merged
merged 4 commits into from
Jan 26, 2018
Merged
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
2 changes: 1 addition & 1 deletion examples/using-remark/src/templates/template-tag-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TagRoute extends React.Component {
<div>
<h1>
{this.props.data.allMarkdownRemark.totalCount}
{` `}posts tagged with “{this.props.pathContext.tag}”
{` `}posts tagged with “{this.props.pageContext.tag}”
</h1>
<ul>{postLinks}</ul>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GatsbyRemarkCodeReplsRedirect extends Component {
}

render() {
const { action, payload } = this.props.pathContext
const { action, payload } = this.props.pageContext

return (
<form
Expand All @@ -33,7 +33,7 @@ class GatsbyRemarkCodeReplsRedirect extends Component {
}

GatsbyRemarkCodeReplsRedirect.propTypes = {
pathContext: PropTypes.shape({
pageContext: PropTypes.shape({
action: PropTypes.string.isRequired,
payload: PropTypes.object.isRequired,
}).isRequired,
Expand Down
34 changes: 19 additions & 15 deletions packages/gatsby/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,26 @@ module.exports = async (program: any) => {
}

function printDeprecationWarnings() {
const files = glob
.sync(`{,!(node_modules|public)/**/}*.js`)
.filter(
file => fs.readFileSync(file).indexOf(`boundActionCreators`) !== -1
)
const deprecatedApis = ["boundActionCreators", "pathContext"];
const deprecatedLocations = {};
deprecatedApis.forEach(api => deprecatedLocations[api] = [])

glob
.sync("{,!(node_modules|public)/**/}*.js")
.forEach(file => {
const fileText = fs.readFileSync(file)
const matchingApis = deprecatedApis.filter(api => fileText.indexOf(api) !== -1)
matchingApis.forEach(api => deprecatedLocations[api].push(file))
})

if (files.length) {
console.log(
`${chalk.cyan(`boundActionCreators`)} ${chalk.yellow(
`is deprecated but was found in the following files:`
)}`
)
console.log()
files.forEach(file => console.log(file))
console.log()
}
deprecatedApis.forEach(api =>{
if (deprecatedLocations[api].length) {
console.log(`${chalk.cyan(api)} ${chalk.yellow(`is deprecated but was found in the following files:`)}`)
console.log()
deprecatedLocations[api].forEach(file => console.log(file))
console.log()
}
})
}

let isFirstCompile = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ module.exports = async (pageOrLayout, component) => {
}

// Add the path/layout context onto the results.
let contextKey = `pathContext`
if (!pageOrLayout.path) {
contextKey = `layoutContext`
result[`layoutContext`] = pageOrLayout.context
} else {
result[`pageContext`] = pageOrLayout.context
}
result[contextKey] = pageOrLayout.context
const resultJSON = JSON.stringify(result)
const resultHash = md5(resultJSON)
const resultPath = joinPath(
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const pascalCase = _.flow(_.camelCase, _.upperFirst)
* @param {string} page.path Any valid URL. Must start with a forward slash
* @param {string} page.component The absolute path to the component for this page
* @param {Object} page.context Context data for this page. Passed as props
* to the component `this.props.pathContext` as well as to the graphql query
* to the component `this.props.pageContext` as well as to the graphql query
* as graphql arguments.
* @example
* createPage({
Expand Down