Skip to content

Commit

Permalink
chore(gatsby): Migrate reducers/index to TypeScript (#23877)
Browse files Browse the repository at this point in the history
* Change file extension from JS to TS

* Change reducer config export to ES6 module

* Change imports and exports to ES6 modules

* Change reducers import on redux index to use ES6 modules

* Update reducers imports and exports

* Comment unused codes

* Update merge conflicts

* Update nodesReducer module name

* Update last-action state type

* Fix merge conflicts

* Revert api test snapshot

* ops, actually fix merge conflicts

Co-authored-by: Michal Piechowiak <[email protected]>
  • Loading branch information
alisson-suzigan and pieh authored Jun 2, 2020
1 parent 75f059e commit 3aec087
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 67 deletions.
16 changes: 8 additions & 8 deletions packages/gatsby/src/redux/__tests__/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { actions } from "../actions"
import { nodeReducer } from "../reducers/nodes"
import { nodesReducer } from "../reducers/nodes"
import { IGatsbyNode } from "../types"
import { nodesTouchedReducer } from "../reducers/nodes-touched"

Expand Down Expand Up @@ -43,7 +43,7 @@ describe(`Create and update nodes`, (): void => {
expect(action).toMatchSnapshot({
payload: { internal: { counter: expect.any(Number) } },
})
expect(fromMapToObject(nodeReducer(undefined, action))).toMatchSnapshot({
expect(fromMapToObject(nodesReducer(undefined, action))).toMatchSnapshot({
hi: { internal: { counter: expect.any(Number) } },
})
})
Expand Down Expand Up @@ -98,8 +98,8 @@ describe(`Create and update nodes`, (): void => {
)(dispatch)
const updateAction = dispatch.mock.calls[1][0]

let state = nodeReducer(undefined, action)
state = nodeReducer(state, updateAction)
let state = nodesReducer(undefined, action)
state = nodesReducer(state, updateAction)

expect(state.get(`hi`)!.pickle).toEqual(false)
expect((state.get(`hi`)!.deep as any).array![0]).toEqual(1)
Expand Down Expand Up @@ -148,7 +148,7 @@ describe(`Create and update nodes`, (): void => {
}
)(dispatch)
const action = dispatch.mock.calls[0][0]
let state = nodeReducer(undefined, action)
let state = nodesReducer(undefined, action)

const addFieldAction = actions.createNodeField(
{
Expand All @@ -161,7 +161,7 @@ describe(`Create and update nodes`, (): void => {
}
)

state = nodeReducer(state, addFieldAction)
state = nodesReducer(state, addFieldAction)
expect(fromMapToObject(state)).toMatchSnapshot({
hi: { internal: { counter: expect.any(Number) } },
})
Expand All @@ -184,7 +184,7 @@ describe(`Create and update nodes`, (): void => {
}
)(dispatch)
const action = dispatch.mock.calls[0][0]
let state = nodeReducer(undefined, action)
let state = nodesReducer(undefined, action)

const addFieldAction = actions.createNodeField(
{
Expand All @@ -196,7 +196,7 @@ describe(`Create and update nodes`, (): void => {
name: `test`,
}
)
state = nodeReducer(state, addFieldAction)
state = nodesReducer(state, addFieldAction)

function callActionCreator(): void {
actions.createNodeField(
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import _ from "lodash"

import { mett } from "../utils/mett"
import thunk from "redux-thunk"
import reducers from "./reducers"
import * as reducers from "./reducers"
import { writeToCache, readFromCache } from "./persist"
import { IGatsbyState, ActionsUnion } from "./types"

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/reducers/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IGatsbyConfig, ISetSiteConfig } from "../types"

module.exports = (
export const configReducer = (
state: IGatsbyConfig = {},
action: ISetSiteConfig
): IGatsbyConfig => {
Expand Down
54 changes: 0 additions & 54 deletions packages/gatsby/src/redux/reducers/index.js

This file was deleted.

58 changes: 58 additions & 0 deletions packages/gatsby/src/redux/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { nodesReducer } from "./nodes"
import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer"
import { pagesReducer } from "./pages"
import { redirectsReducer } from "./redirects"
import { schemaReducer } from "./schema"
import { staticQueryComponentsReducer } from "./static-query-components"
import { statusReducer } from "./status"
import { webpackReducer } from "./webpack"
import { pageDataReducer } from "./page-data"
import { themesReducer } from "./themes"
import { webpackCompilationHashReducer } from "./webpack-compilation-hash"
import { configReducer } from "./config"
import { lastActionReducer } from "./last-action"
import { jobsV2Reducer } from "./jobsv2"
import { pageDataStatsReducer } from "./page-data-stats"
import { componentsReducer } from "./components"
import { componentDataDependenciesReducer } from "./component-data-dependencies"
import { babelrcReducer } from "./babelrc"
import { jobsReducer } from "./jobs"
import { nodesByTypeReducer } from "./nodes-by-type"
import programReducer from "./program"
import { resolvedNodesCacheReducer } from "./resolved-nodes"
import { nodesTouchedReducer } from "./nodes-touched"
import { flattenedPluginsReducer } from "./flattened-plugins"
import schemaCustomizationReducer from "./schema-customization"
import inferenceMetadataReducer from "./inference-metadata"

/**
* @property exports.nodesTouched Set<string>
*/
export {
programReducer as program,
nodesReducer as nodes,
nodesByTypeReducer as nodesByType,
resolvedNodesCacheReducer as resolvedNodesCache,
nodesTouchedReducer as nodesTouched,
lastActionReducer as lastAction,
flattenedPluginsReducer as flattenedPlugins,
configReducer as config,
schemaReducer as schema,
pagesReducer as pages,
statusReducer as status,
componentDataDependenciesReducer as componentDataDependencies,
componentsReducer as components,
staticQueryComponentsReducer as staticQueryComponents,
jobsReducer as jobs,
jobsV2Reducer as jobsV2,
webpackReducer as webpack,
webpackCompilationHashReducer as webpackCompilationHash,
redirectsReducer as redirects,
babelrcReducer as babelrc,
schemaCustomizationReducer as schemaCustomization,
themesReducer as themes,
logReducer as logs,
inferenceMetadataReducer as inferenceMetadata,
pageDataStatsReducer as pageDataStats,
pageDataReducer as pageData,
}
4 changes: 2 additions & 2 deletions packages/gatsby/src/redux/reducers/last-action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IGatsbyState, ActionsUnion } from "../types"

export const lastAction = (
_state: IGatsbyState["lastAction"],
export const lastActionReducer = (
_state: unknown,
action: ActionsUnion
): IGatsbyState["lastAction"] => action
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/reducers/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionsUnion, IGatsbyState } from "../types"

export const nodeReducer = (
export const nodesReducer = (
state: IGatsbyState["nodes"] = new Map(),
action: ActionsUnion
): IGatsbyState["nodes"] => {
Expand Down

0 comments on commit 3aec087

Please sign in to comment.