From a8108abae4e5e1c04b97b3bc63b6627a3ad796bc Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 30 May 2017 11:33:41 -0700 Subject: [PATCH] rename internal APIs --- packages/gatsby/src/bootstrap/index.js | 2 + .../gatsby/src/query-runner/query-watcher.js | 8 +-- packages/gatsby/src/redux/actions.js | 50 +++++++++++++------ .../__tests__/page-data-dependencies.js | 18 +++---- .../src/redux/reducers/page-components.js | 4 +- .../redux/reducers/page-data-dependencies.js | 4 +- www/src/pages/docs/action-creators.js | 1 - 7 files changed, 54 insertions(+), 33 deletions(-) diff --git a/packages/gatsby/src/bootstrap/index.js b/packages/gatsby/src/bootstrap/index.js index 69fcea54197d9..ca31fea232537 100644 --- a/packages/gatsby/src/bootstrap/index.js +++ b/packages/gatsby/src/bootstrap/index.js @@ -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({ diff --git a/packages/gatsby/src/query-runner/query-watcher.js b/packages/gatsby/src/query-runner/query-watcher.js index 4dafcfddd0496..2ea7e398f6c4a 100644 --- a/packages/gatsby/src/query-runner/query-watcher.js +++ b/packages/gatsby/src/query-runner/query-watcher.js @@ -29,7 +29,7 @@ const debounceNewPages = _.debounce(() => { pages.forEach(componentPath => { const query = queries.get(componentPath) - boundActionCreators.setPageComponentQuery({ + boundActionCreators.replacePageComponentQuery({ query: query && query.text, componentPath, }) @@ -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) @@ -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))) } @@ -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, }) diff --git a/packages/gatsby/src/redux/actions.js b/packages/gatsby/src/redux/actions.js index 58acbd20cfb27..9243f5bcad39f 100644 --- a/packages/gatsby/src/redux/actions.js +++ b/packages/gatsby/src/redux/actions.js @@ -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, @@ -339,6 +339,7 @@ actions.createParentChildLink = ({ parent, child }, plugin) => { } } +// Change to "setPluginStatus". actions.updateSourcePluginStatus = (status, plugin = ``) => { return { type: `UPDATE_SOURCE_PLUGIN_STATUS`, @@ -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, @@ -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, diff --git a/packages/gatsby/src/redux/reducers/__tests__/page-data-dependencies.js b/packages/gatsby/src/redux/reducers/__tests__/page-data-dependencies.js index 497faf5244f64..0c24c0e0fcad2 100644 --- a/packages/gatsby/src/redux/reducers/__tests__/page-data-dependencies.js +++ b/packages/gatsby/src/redux/reducers/__tests__/page-data-dependencies.js @@ -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`, @@ -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`, @@ -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`, @@ -79,7 +79,7 @@ describe(`add page data dependency`, () => { }) it(`removes duplicate paths`, () => { const action = { - type: `ADD_PAGE_DEPENDENCY`, + type: `CREATE_PAGE_DEPENDENCY`, payload: { path: `/hi/`, nodeId: 1, @@ -87,7 +87,7 @@ describe(`add page data dependency`, () => { }, } const action2 = { - type: `ADD_PAGE_DEPENDENCY`, + type: `CREATE_PAGE_DEPENDENCY`, payload: { path: `/hi2/`, nodeId: 1, @@ -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`, diff --git a/packages/gatsby/src/redux/reducers/page-components.js b/packages/gatsby/src/redux/reducers/page-components.js index d56ef2f55da00..236022dcc955d 100644 --- a/packages/gatsby/src/redux/reducers/page-components.js +++ b/packages/gatsby/src/redux/reducers/page-components.js @@ -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, diff --git a/packages/gatsby/src/redux/reducers/page-data-dependencies.js b/packages/gatsby/src/redux/reducers/page-data-dependencies.js index 917a08d05bfab..6d7f470393969 100644 --- a/packages/gatsby/src/redux/reducers/page-data-dependencies.js +++ b/packages/gatsby/src/redux/reducers/page-data-dependencies.js @@ -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 } @@ -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) ) diff --git a/www/src/pages/docs/action-creators.js b/www/src/pages/docs/action-creators.js index b6b1e39d5ae5c..7e6a9b6e44f79 100644 --- a/www/src/pages/docs/action-creators.js +++ b/www/src/pages/docs/action-creators.js @@ -8,7 +8,6 @@ const Param = (param, depth = 0) => { return null } - console.log(param) return (