Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): Migrate reducers/index to TypeScript #23877

Merged
merged 21 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db2415a
Change file extension from JS to TS
alisson-suzigan May 7, 2020
b8e8b52
Change reducer config export to ES6 module
alisson-suzigan May 7, 2020
17a3975
Change imports and exports to ES6 modules
alisson-suzigan May 7, 2020
ab2e67b
Change reducers import on redux index to use ES6 modules
alisson-suzigan May 7, 2020
1712892
Update reducers imports and exports
alisson-suzigan May 8, 2020
88b43b8
Comment unused codes
alisson-suzigan May 8, 2020
ab973bb
Merge branch 'master' into ts/reducers-index
alisson-suzigan May 8, 2020
810e5d0
Update merge conflicts
alisson-suzigan May 8, 2020
1f499c0
Merge branch 'master' into ts/reducers-index
alisson-suzigan May 9, 2020
5afbebb
Update nodesReducer module name
alisson-suzigan May 9, 2020
ca84802
Update last-action state type
alisson-suzigan May 9, 2020
6304a37
Fix conflicts from new PRs
alisson-suzigan May 12, 2020
d092a5c
Fix merge conflicts
alisson-suzigan May 12, 2020
b5f9f67
Fix conflicts coming from the last RPs
alisson-suzigan May 16, 2020
b1a93fc
Fix conflicts coming from new RPs
alisson-suzigan May 19, 2020
1ee7d78
Merge branch 'master' into ts/reducers-index
alisson-suzigan May 19, 2020
d0642db
Merge branch 'master' into ts/reducers-index
alisson-suzigan May 20, 2020
9bab534
Revert api test snapshot
alisson-suzigan May 20, 2020
6e628cb
Merge branch 'master' into ts/reducers-index
alisson-suzigan May 24, 2020
c967d0e
Merge remote-tracking branch 'origin/master' into ts/reducers-index
pieh Jun 2, 2020
11d8d07
ops, actually fix merge conflicts
pieh Jun 2, 2020
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
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,
pieh marked this conversation as resolved.
Show resolved Hide resolved
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