Skip to content

Commit

Permalink
rename internal APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed May 30, 2017
1 parent 9e1c25a commit a8108ab
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 33 deletions.
2 changes: 2 additions & 0 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ data

// Collect resolvable extensions and attach to program.
const extensions = [`.js`, `.jsx`]
// Change to this being an action and plugins implement `onPreBootstrap`
// for adding extensions.
const apiResults = await apiRunnerNode(`resolvableExtensions`)

store.dispatch({
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby/src/query-runner/query-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const debounceNewPages = _.debounce(() => {
pages.forEach(componentPath => {
const query = queries.get(componentPath)

boundActionCreators.setPageComponentQuery({
boundActionCreators.replacePageComponentQuery({
query: query && query.text,
componentPath,
})
Expand Down Expand Up @@ -62,7 +62,7 @@ emitter.on(`CREATE_PAGE`, action => {
if (!fs.existsSync(pathToJSONFile)) {
fs.writeFile(pathToJSONFile, `{}`)
}
boundActionCreators.addPageComponent(component)
boundActionCreators.createPageComponent(component)
pendingPages.push(component)
// Make sure we're watching this component.
watcher.add(component)
Expand All @@ -78,7 +78,7 @@ const runQueriesForComponent = componentPath => {
// Remove page data dependencies before re-running queries because
// the changing of the query could have changed the data dependencies.
// Re-running the queries will add back data dependencies.
boundActionCreators.removePagesDataDependencies(pages.map(p => p.path))
boundActionCreators.deletePagesDependencies(pages.map(p => p.path))
const component = store.getState().pageComponents[componentPath]
return Promise.all(pages.map(p => queryRunner(p, component)))
}
Expand All @@ -95,7 +95,7 @@ exports.watch = rootDir => {
const pages = store.getState().pageComponents
queries.forEach(({ text }, path) => {
if (text !== pages[path].query) {
boundActionCreators.setPageComponentQuery({
boundActionCreators.replacePageComponentQuery({
query: text,
componentPath: path,
})
Expand Down
50 changes: 35 additions & 15 deletions packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ actions.createNode = (node, 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} $0
* @param {Object} $0.node the target node object
* @param {String} $0.fieldName the name for the field
* @param {String} $0.fieldValue the value for the field
* @param {object} $0
* @param {object} $0.node the target node object
* @param {string} $0.fieldName the name for the field
* @param {string} $0.fieldValue the value for the field
* @example
* createNodeField({
* node,
Expand Down Expand Up @@ -339,6 +339,7 @@ actions.createParentChildLink = ({ parent, child }, plugin) => {
}
}

// Change to "setPluginStatus".
actions.updateSourcePluginStatus = (status, plugin = ``) => {
return {
type: `UPDATE_SOURCE_PLUGIN_STATUS`,
Expand All @@ -350,14 +351,15 @@ actions.updateSourcePluginStatus = (status, plugin = ``) => {
/**
* Create a dependency between a page and data. Probably for
* internal use only.
* @param {Object} $0
* @param {Object} $0.path the path to the page
* @param {String} $0.nodeId A node ID
* @param {String} $0.connection A connection type
* @param {object} $0
* @param {string} $0.path the path to the page
* @param {string} $0.nodeId A node ID
* @param {string} $0.connection A connection type
* @private
*/
actions.createPageDependency = ({ path, nodeId, connection }, plugin = ``) => {
return {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
plugin,
payload: {
path,
Expand All @@ -367,27 +369,45 @@ actions.createPageDependency = ({ path, nodeId, connection }, plugin = ``) => {
}
}

actions.removePagesDataDependencies = paths => {
/**
* Delete dependencies between an array of pages and data. Probably for
* internal use only. Used when deleting pages.
* @param {object} $0
* @param {array} $0.paths the paths to delete.
* @private
*/
actions.deletePagesDependencies = paths => {
return {
type: `REMOVE_PAGES_DATA_DEPENDENCIES`,
type: `DELETE_PAGES_DEPENDENCIES`,
payload: {
paths,
},
}
}

actions.addPageComponent = componentPath => {
/**
* Used by the query watcher when it identifies a new component
* which is probably a page. TODO perhaps the query watcher
* just listens for new pages?
* @private
*/
actions.createPageComponent = componentPath => {
return {
type: `ADD_PAGE_COMPONENT`,
type: `CREATE_PAGE_COMPONENT`,
payload: {
componentPath,
},
}
}

actions.setPageComponentQuery = ({ query, componentPath }) => {
/**
* When the query watcher extracts a graphq query, it calls
* this to store the query with its component.
* @private
*/
actions.replacePageComponentQuery = ({ query, componentPath }) => {
return {
type: `SET_PAGE_COMPONENT_QUERY`,
type: `REPLACE_PAGE_COMPONENT_QUERY`,
payload: {
query,
componentPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const reducer = require(`../page-data-dependencies`)
describe(`add page data dependency`, () => {
it(`lets you add a node dependency`, () => {
const action = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi/`,
nodeId: `123`,
Expand All @@ -19,21 +19,21 @@ describe(`add page data dependency`, () => {
})
it(`lets you add a node dependency to multiple paths`, () => {
const action = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi/`,
nodeId: `1.2.3`,
},
}
const action2 = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi2/`,
nodeId: `1.2.3`,
},
}
const action3 = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/blog/`,
nodeId: `1.2.3`,
Expand All @@ -53,14 +53,14 @@ describe(`add page data dependency`, () => {
})
it(`lets you add a connection dependency`, () => {
const action = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi/`,
connection: `Markdown.Remark`,
},
}
const action2 = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi2/`,
connection: `Markdown.Remark`,
Expand All @@ -79,15 +79,15 @@ describe(`add page data dependency`, () => {
})
it(`removes duplicate paths`, () => {
const action = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi/`,
nodeId: 1,
connection: `MarkdownRemark`,
},
}
const action2 = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi2/`,
nodeId: 1,
Expand All @@ -106,7 +106,7 @@ describe(`add page data dependency`, () => {
})
it(`lets you add both a node and connection in one action`, () => {
const action = {
type: `ADD_PAGE_DEPENDENCY`,
type: `CREATE_PAGE_DEPENDENCY`,
payload: {
path: `/hi/`,
connection: `MarkdownRemark`,
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/redux/reducers/page-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module.exports = (state = {}, action) => {
switch (action.type) {
case `DELETE_CACHE`:
return {}
case `ADD_PAGE_COMPONENT`:
case `CREATE_PAGE_COMPONENT`:
if (!_.has(state, `action.payload.componentPath`)) {
state[action.payload.componentPath] = {
componentPath: action.payload.componentPath,
}
}
return state
case `SET_PAGE_COMPONENT_QUERY`:
case `REPLACE_PAGE_COMPONENT_QUERY`:
state[action.payload.componentPath] = {
...state[action.payload.componentPath],
query: action.payload.query,
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/redux/reducers/page-data-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = (state = { nodes: {}, connections: {} }, action) => {
switch (action.type) {
case `DELETE_CACHE`:
return { nodes: {}, connections: {} }
case `ADD_PAGE_DEPENDENCY`:
case `CREATE_PAGE_DEPENDENCY`:
if (action.payload.path === ``) {
return state
}
Expand All @@ -30,7 +30,7 @@ module.exports = (state = { nodes: {}, connections: {} }, action) => {
}

return state
case `REMOVE_PAGES_DATA_DEPENDENCIES`:
case `DELETE_PAGES_DEPENDENCIES`:
state.nodes = _.mapValues(state.nodes, paths =>
_.difference(paths, action.payload.paths)
)
Expand Down
1 change: 0 additions & 1 deletion www/src/pages/docs/action-creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const Param = (param, depth = 0) => {
return null
}

console.log(param)
return (
<div
css={{
Expand Down

0 comments on commit a8108ab

Please sign in to comment.