-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.0] Factor out node sourcing code into its own module (#1083)
* Factor out sourcing nodes into its own module * Add explicit mapping for highlight.js cause jest can't find it for whatever reason
- Loading branch information
1 parent
e0f2b89
commit a64ddc0
Showing
4 changed files
with
52 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const _ = require(`lodash`) | ||
|
||
const apiRunner = require(`./api-runner-node`) | ||
const { store, getNode } = require(`../redux`) | ||
const { boundActionCreators } = require(`../redux/actions`) | ||
const { deleteNodes } = boundActionCreators | ||
|
||
module.exports = async () => { | ||
await apiRunner(`sourceNodes`, { | ||
traceId: `initial-sourceNodes`, | ||
waitForCascadingActions: true, | ||
}) | ||
|
||
const state = store.getState() | ||
|
||
// Garbage collect stale data nodes | ||
const touchedNodes = Object.keys(state.nodesTouched) | ||
const staleNodes = _.values(state.nodes).filter(node => { | ||
// Find the root node. | ||
let rootNode = node | ||
let whileCount = 0 | ||
while ( | ||
rootNode.parent && | ||
getNode(rootNode.parent) !== undefined && | ||
whileCount < 101 | ||
) { | ||
rootNode = getNode(rootNode.parent) | ||
whileCount += 1 | ||
if (whileCount > 100) { | ||
console.log( | ||
`It looks like you have a node that's set its parent as itself`, | ||
rootNode | ||
) | ||
} | ||
} | ||
|
||
return !_.includes(touchedNodes, rootNode.id) | ||
}) | ||
|
||
if (staleNodes.length > 0) { | ||
deleteNodes(staleNodes.map(n => n.id)) | ||
} | ||
} |