Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 10 additions & 11 deletions packages/gatsby/src/redux/reducers/components.js
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down