Skip to content

Commit

Permalink
MORE WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Feb 19, 2019
1 parent 190625f commit 890fb36
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const { store, emitter } = require(`../../redux`)
let queuedDirtyActions = []

let active = false
let running = false

const runQueriesForPathnamesQueue = new Set()
exports.queueQueryForPathname = pathname => {
Expand Down Expand Up @@ -50,6 +49,7 @@ const runQueries = async () => {
...dirtyIds,
...cleanIds,
])
console.log({ pathnamesToRun })

runQueriesForPathnamesQueue.clear()

Expand All @@ -73,12 +73,13 @@ emitter.on(`CREATE_PAGE`, action => {
})

const runQueuedActions = async () => {
if (active && !running) {
console.log(`runQueuedActions`, { active })
if (active) {
try {
running = true
await runQueries()
} finally {
running = false
// TODO what does this mean?
// Why "finally"?
if (queuedDirtyActions.length > 0) {
runQueuedActions()
}
Expand Down Expand Up @@ -155,6 +156,10 @@ const runQueriesForPathnames = pathnames => {
let didNotQueueItems = true
pageQueries.forEach(id => {
const page = pages.get(id)
console.log({
page,
component: store.getState().components.get(page.componentPath),
})
// Don't run queries for page components that haven't yet
// had their queries extracted. Once that is finished, the pages
// with using that component will have their queries queued again.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const chokidar = require(`chokidar`)
const path = require(`path`)
const slash = require(`slash`)

const { store } = require(`../../redux/`)
const { store, emitter } = require(`../../redux/`)
const { boundActionCreators } = require(`../../redux/actions`)
const queryCompiler = require(`./query-compiler`).default
const report = require(`gatsby-cli/lib/reporter`)
Expand Down Expand Up @@ -70,11 +70,15 @@ const handlePageComponentsWithNoQueries = ({ components }, queries) => {
components.forEach(c => {
if (c.queryState === `QUERY_NOT_YET_EXTRACTED`) {
boundActionCreators.replaceComponentQuery({
query: ``,
queryState: `QUERY_EXTRACTED`,
componentPath: c.componentPath,
})
queueQueriesForPageComponent(c.componentPath)
}
})
console.log({ runQueuedQueries })
runQueuedQueries()
}

const handleQuery = (
Expand Down Expand Up @@ -145,7 +149,7 @@ const updateStateAndRunQueries = isFirstRun => {
const snapshot = getQueriesSnapshot()
return queryCompiler().then(queries => {
handleComponentsWithRemovedQueries(snapshot, queries)
handleComponentsWithNoQueries(snapshot, queries)
handlePageComponentsWithNoQueries(snapshot, queries)

let queriesWillNotRun = false
queries.forEach((query, component) => {
Expand Down Expand Up @@ -228,6 +232,7 @@ exports.extractQueries = () => {
}

const queueQueriesForPageComponent = componentPath => {
console.log(`queueQueriesForPageComponent`, { componentPath })
const pages = getPagesForComponent(componentPath)
// Remove page data dependencies before re-running queries because
// the changing of the query could have changed the data dependencies.
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/reducers/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module.exports = (state = new Map(), action) => {
)
action.payload.componentPath = normalize(action.payload.componentPath)
state.set(action.payload.componentPath, {
queryState: `QUERY_EXTRACTED`,
...state.get(action.payload.componentPath),
query: action.payload.query,
queryState: `QUERY_EXTRACTED`,
})
return state
}
Expand Down

0 comments on commit 890fb36

Please sign in to comment.