diff --git a/packages/gatsby/src/internal-plugins/query-runner/gatsby-node.js b/packages/gatsby/src/internal-plugins/query-runner/gatsby-node.js index 2f021f5bd1782..257a2226f8ec4 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/query-runner/gatsby-node.js @@ -3,7 +3,7 @@ const { watchComponent } = require(`./query-watcher`) let components = {} exports.onCreatePage = ({ page, store }) => { - const component = store.getState().components[page.componentPath] + const component = store.getState().components.get(page.componentPath) if (components[component.componentPath]) { return diff --git a/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js b/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js index 4ed2677711c83..c73dad1e24ca7 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js +++ b/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js @@ -125,7 +125,7 @@ const runQueriesForPathnames = pathnames => { ({ id: page.path, jsonName: page.jsonName, - query: store.getState().components[page.componentPath].query, + query: store.getState().components.get(page.componentPath).query, isPage: true, componentPath: page.componentPath, context: { diff --git a/packages/gatsby/src/internal-plugins/query-runner/query-compiler.js b/packages/gatsby/src/internal-plugins/query-runner/query-compiler.js index 5e0f38ec24ca1..6821940280239 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/query-compiler.js +++ b/packages/gatsby/src/internal-plugins/query-runner/query-compiler.js @@ -103,7 +103,7 @@ class Runner { // run babel on code in node_modules). Otherwise the component will throw // an error in the browser of "graphql is not defined". files = files.concat( - Object.keys(store.getState().components).map(c => normalize(c)) + Array.from(store.getState().components.keys(), c => normalize(c)) ) files = _.uniq(files) diff --git a/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js b/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js index 8ed79bc415271..515a0a4c35c4d 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js +++ b/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js @@ -94,7 +94,7 @@ const runQueriesForPageComponent = componentPath => { queue.push({ id: page.path, jsonName: page.jsonName, - query: store.getState().components[componentPath].query, + query: store.getState().components.get(componentPath).query, isPage: true, context: { ...page, @@ -141,7 +141,7 @@ const watch = rootDir => { // If a component previously with a query now doesn't — update the // store. - const noQueryComponents = Object.values(components).filter( + const noQueryComponents = Array.from(components.values()).filter( c => c.query !== `` && !queries.has(c.componentPath) ) noQueryComponents.forEach(({ componentPath }) => { @@ -177,7 +177,7 @@ const watch = rootDir => { // // If the query has changed, set the new query in the // store and run its queries. - if (components[id] && text !== components[id].query) { + if (components.has(id) && text !== components.get(id).query) { boundActionCreators.replaceComponentQuery({ query: text, componentPath: id, diff --git a/packages/gatsby/src/redux/reducers/components.js b/packages/gatsby/src/redux/reducers/components.js index 62b5e36d38929..0af9c9c253448 100644 --- a/packages/gatsby/src/redux/reducers/components.js +++ b/packages/gatsby/src/redux/reducers/components.js @@ -1,30 +1,29 @@ const _ = require(`lodash`) const normalize = require(`normalize-path`) -module.exports = (state = {}, action) => { +module.exports = (state = new Map(), action) => { switch (action.type) { case `DELETE_CACHE`: - return {} + return new Map() case `CREATE_PAGE`: action.payload.componentPath = normalize(action.payload.component) - state[action.payload.componentPath] = _.merge( - { query: `` }, - state[action.payload.componentPath], - { + state.set( + action.payload.componentPath, + _.merge({ query: `` }, state.get(action.payload.componentPath), { componentPath: action.payload.componentPath, - } + }) ) return state case `DELETE_PAGE`: action.payload.componentPath = normalize(action.payload.component) - delete state[action.payload.componentPath] + state.delete(action.payload.componentPath) return state case `REPLACE_COMPONENT_QUERY`: action.payload.componentPath = normalize(action.payload.componentPath) - state[action.payload.componentPath] = { - ...state[action.payload.componentPath], + state.set(action.payload.componentPath, { + ...state.get(action.payload.componentPath), query: action.payload.query, - } + }) return state }