Skip to content

Commit

Permalink
[v2] Deprecate pathContext in favor of pageContext (#3515)
Browse files Browse the repository at this point in the history
* replace pageContext for pathContext

* deprecate path context for page context

* changes more instances in packages and examples

* breaking change
  • Loading branch information
calcsam authored Jan 26, 2018
1 parent d6070ef commit 0e8bd14
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
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

0 comments on commit 0e8bd14

Please sign in to comment.