Skip to content

Commit

Permalink
[v2] deleteNode signature (#5222)
Browse files Browse the repository at this point in the history
* Change deleteNode signature to remove nodeId

* These tests were failing?

* Deprecate old deleteNode method signature

* Change touchNode to accept an object
  • Loading branch information
m-allanson authored and KyleAMathews committed May 10, 2018
1 parent 82c103b commit 63168df
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 360 deletions.
6 changes: 3 additions & 3 deletions packages/gatsby-source-contentful/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ exports.sourceNodes = async (
// Remove deleted entries & assets.
// TODO figure out if entries referencing now deleted entries/assets
// are "updated" so will get the now deleted reference removed.
currentSyncData.deletedEntries.forEach(e => deleteNode(e.sys.id, e.sys))
currentSyncData.deletedAssets.forEach(e => deleteNode(e.sys.id, e.sys))
currentSyncData.deletedEntries.forEach(e => deleteNode({ node: e.sys }))
currentSyncData.deletedAssets.forEach(e => deleteNode({ node: e.sys }))

const existingNodes = getNodes().filter(
n => n.internal.owner === `gatsby-source-contentful`
)
existingNodes.forEach(n => touchNode(n.id))
existingNodes.forEach(n => touchNode({ nodeId: n.id }))

const assets = currentSyncData.assets

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.sourceNodes = async (
// Touch existing Drupal nodes so Gatsby doesn't garbage collect them.
// _.values(store.getState().nodes)
// .filter(n => n.internal.type.slice(0, 8) === `drupal__`)
// .forEach(n => touchNode(n.id))
// .forEach(n => touchNode({ nodeId: n.id }))

// Fetch articles.
// console.time(`fetch Drupal data`)
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-source-filesystem/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ See docs here - https://www.gatsbyjs.org/packages/gatsby-source-filesystem/
// write and then immediately delete temporary files to the file system.
if (node) {
currentState = fsMachine.transition(currentState.value, `EMIT_FS_EVENT`)
deleteNode(node.id, node)
deleteNode({ node })
}
})

Expand All @@ -212,7 +212,7 @@ See docs here - https://www.gatsbyjs.org/packages/gatsby-source-filesystem/
reporter.info(`directory deleted at ${path}`)
}
const node = getNode(createNodeId(path))
deleteNode(node.id, node)
deleteNode({ node })
})

return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-wordpress/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ exports.downloadMediaFiles = async ({
// previously created file node to not try to redownload
if (cacheMediaData && e.modified === cacheMediaData.modified) {
fileNodeID = cacheMediaData.fileNodeID
touchNode(cacheMediaData.fileNodeID)
touchNode({ nodeId: cacheMediaData.fileNodeID })
}

// If we don't have cached data, download the file
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-transformer-screenshot/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports.onPreBootstrap = (
} else {
// Screenshot hasn't yet expired, touch the image node
// to prevent garbage collection
touchNode(n.screenshotFile___NODE)
touchNode({ nodeId: n.screenshotFile___NODE })
}
})
)
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ const queue = {
},

addPagesArray: newPages => {
if (__PREFIX_PATHS__) {
pathPrefix = `${__PATH_PREFIX__}/`
if (typeof __PREFIX_PATHS__ !== `undefined`) {
pathPrefix = typeof __PATH_PREFIX__ !== `undefined` ? `${__PATH_PREFIX__}/` : `/`
}
findPage = pageFinderFactory(newPages, pathPrefix.slice(0, -1))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ exports.onCreatePage = ({ page, actions }) => {
emitter.on(`DELETE_PAGE`, action => {
const nodeId = createPageId(action.payload.path)
const node = getNode(nodeId)
boundActionCreators.deleteNode(nodeId, node)
boundActionCreators.deleteNode({ node })
})
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ emitter.on(`CREATE_NODE`, action => {
})

emitter.on(`DELETE_NODE`, action => {
queuedDirtyActions.push({ payload: action.node })
queuedDirtyActions.push({ payload: action.payload })
})

const runQueuedActions = async () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/gatsby/src/redux/__tests__/__snapshots__/nodes.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,16 @@ exports[`Create and update nodes throws error if a node sets a value on "fields"
\\"name\\": \\"pluginA\\"
}"
`;

exports[`Create and update nodes warns when using old deleteNode signature 1`] = `
Object {
"children": Array [],
"id": "hi",
"internal": Object {
"contentDigest": "hasdfljds",
"owner": "tests",
"type": "Test",
},
"parent": "test",
}
`;
Loading

0 comments on commit 63168df

Please sign in to comment.