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

[1.0] Refactor and document APIs #1053

Merged
merged 23 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b46a59b
Add basic version of new documentation.js transformer
KyleAMathews May 28, 2017
ab7ba98
Change api 'addFieldToNode' to 'createNodeField'
KyleAMathews May 29, 2017
45f7a31
Fix up node creation and add some simple tests
KyleAMathews May 30, 2017
1067771
Get basic docs page for action creators up
KyleAMathews May 30, 2017
0e39282
change deletePageByPath to just deletePage also sort action creators …
KyleAMathews May 30, 2017
d27833d
Change 'upsertPage' to 'createPage' and document it
KyleAMathews May 30, 2017
8a7575d
Only hide parent object description if its a desctructured object + i…
KyleAMathews May 30, 2017
61b79ff
Update action type
KyleAMathews May 30, 2017
776f77d
Support third level of parameters
KyleAMathews May 30, 2017
8863d25
Document createNode
KyleAMathews May 30, 2017
3697716
change 'addNodeToParent' to 'createParentChildLink' and document
KyleAMathews May 30, 2017
9e1c25a
Change 'addPageDependency' to 'createPageDependency' and document
KyleAMathews May 30, 2017
a8108ab
rename internal APIs
KyleAMathews May 30, 2017
5b0528b
Add links from function names at top to reference
KyleAMathews May 30, 2017
cba9b46
Ignore yarn.lock
KyleAMathews May 30, 2017
3ad7e09
Don't change the changelog...
KyleAMathews May 30, 2017
3c77aa3
Document and slightly modify node APIs
KyleAMathews May 31, 2017
6acd904
Factor out a FunctionsList component for rendering function docs
KyleAMathews May 31, 2017
6d536b3
Add browser/ssr docs and make a few tweaks to APIs
KyleAMathews May 31, 2017
62461fe
Add API specification document
KyleAMathews May 31, 2017
b5d634c
Actually add docs for node/browser/ssr
KyleAMathews May 31, 2017
e6600ab
Tweaks
KyleAMathews May 31, 2017
385bc78
Add README for gatsby-transformer-documentationjs
KyleAMathews May 31, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change api 'addFieldToNode' to 'createNodeField'
  • Loading branch information
KyleAMathews committed May 29, 2017
commit ab7ba9832dde9450077cd06f9cc38fe712bfdae7
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"parser": "babel-eslint",
"extends": [
"google",
"eslint:recommended",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/creating-and-modifying-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ Often you will need to programmatically create pages. For example, you have
markdown files that each should be a page.

TODO finish this once it's more settled how to modify nodes to add slugs and
other special fields that we want to associate with a node. Perhaps `addFieldToNode`.
other special fields that we want to associate with a node. Perhaps `createNodeField`.
4 changes: 2 additions & 2 deletions docs/docs/migrating-from-v0-to-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Here's how you do that.
const path = require('path')

exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
const { addFieldToNode } = boundActionCreators
const { createNodeField } = boundActionCreators
let slug
if (node.internal.type === `MarkdownRemark`) {
const fileNode = getNode(node.parent)
Expand All @@ -148,7 +148,7 @@ exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
}

// Add slug as a field on the node.
addFieldToNode({ node, fieldName: `slug`, fieldValue: slug })
createNodeField({ node, fieldName: `slug`, fieldValue: slug })
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/src/redux/__tests__/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe(`Create and update nodes`, () => {
)
let state = nodeReducer(undefined, action)

const addFieldAction = actions.addFieldToNode(
const addFieldAction = actions.createNodeField(
{
node: state[`hi`],
fieldName: `joy`,
Expand Down Expand Up @@ -138,7 +138,7 @@ describe(`Create and update nodes`, () => {
)
let state = nodeReducer(undefined, action)

const addFieldAction = actions.addFieldToNode(
const addFieldAction = actions.createNodeField(
{
node: state[`hi`],
fieldName: `joy`,
Expand All @@ -149,7 +149,7 @@ describe(`Create and update nodes`, () => {
state = nodeReducer(state, addFieldAction)

function callActionCreator() {
actions.addFieldToNode(
actions.createNodeField(
{
node: state[`hi`],
fieldName: `joy`,
Expand Down
17 changes: 16 additions & 1 deletion packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import Joi from "joi"
import chalk from "chalk"
const _ = require(`lodash`)
Expand Down Expand Up @@ -184,7 +185,21 @@ actions.createNode = (node, plugin) => {
}
}

actions.addFieldToNode = ({ node, fieldName, fieldValue }, plugin) => {
/**
* Create field on a node a plugin don't own. Once a plugin has claimed a field name
* the field name can't be used by other plugins.
* @param {Object} _ref
* @param {Object} _ref.node the target node object
* @param {String} _ref.fieldName the name for the field
* @param {String} _ref.fieldValue the value for the field
* @example
* createNodeField({
* node,
* fieldName: `happiness`,
* fieldValue: `is sweet graphql queries`
* })
*/
actions.createNodeField = ({ node, fieldName, fieldValue }, plugin) => {
// Ensure required fields are set.
if (!node.internal.fieldOwners) {
node.internal.fieldOwners = {}
Expand Down
10 changes: 5 additions & 5 deletions www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {

// Create slugs for files.
exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
const { addFieldToNode } = boundActionCreators
const { createNodeField } = boundActionCreators
let slug
if (node.internal.type === `File`) {
const parsedFilePath = parseFilepath(node.relativePath)
Expand All @@ -83,7 +83,7 @@ exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
}
}
if (slug) {
addFieldToNode({ node, fieldName: `slug`, fieldValue: slug })
createNodeField({ node, fieldName: `slug`, fieldValue: slug })
}
} else if (
node.internal.type === `MarkdownRemark` &&
Expand All @@ -107,15 +107,15 @@ exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
parsedFilePath.name === `README`
) {
slug = `/docs/packages/${parsedFilePath.dir}/`
addFieldToNode({
createNodeField({
node,
fieldName: `title`,
fieldValue: parsedFilePath.dir,
})
addFieldToNode({ node, fieldName: `package`, fieldValue: true })
createNodeField({ node, fieldName: `package`, fieldValue: true })
}
if (slug) {
addFieldToNode({ node, fieldName: `slug`, fieldValue: slug })
createNodeField({ node, fieldName: `slug`, fieldValue: slug })
}
}
}
Expand Down