Skip to content

Commit

Permalink
chore(gatsby): Convert flattened-plugins and resolved-nodes to TS (ga…
Browse files Browse the repository at this point in the history
…tsbyjs#24062)

* Convert flattened-plugins reducer to TS

* Update redux types by adding ISetResolvedNodesAction

* Convert resolved-nodes to TS

* Update redux index import

Co-authored-by: Blaine Kasten <blainekasten@gmail.com>
  • Loading branch information
2 people authored and johno committed May 28, 2020
1 parent 9c1d963 commit 7ad7ac9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
8 changes: 0 additions & 8 deletions packages/gatsby/src/redux/reducers/flattened-plugins.js

This file was deleted.

14 changes: 14 additions & 0 deletions packages/gatsby/src/redux/reducers/flattened-plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IGatsbyState, ActionsUnion } from "../types"

export const flattenedPluginsReducer = (
state: IGatsbyState["flattenedPlugins"] = [],
action: ActionsUnion
): IGatsbyState["flattenedPlugins"] => {
switch (action.type) {
case `SET_SITE_FLATTENED_PLUGINS`:
return [...action.payload]

default:
return state
}
}
6 changes: 4 additions & 2 deletions packages/gatsby/src/redux/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { webpackCompilationHashReducer } from "./webpack-compilation-hash"
import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer"
import { lastAction } from "./last-action"
import { jobsV2Reducer } from "./jobsv2"
import { flattenedPluginsReducer } from "./flattened-plugins"
import { resolvedNodesCacheReducer } from "./resolved-nodes"
import { pageDataStatsReducer } from "./page-data-stats"
import { componentsReducer } from "./components"
import { componentDataDependenciesReducer } from "./component-data-dependencies"
Expand All @@ -26,10 +28,10 @@ module.exports = {
program: require(`./program`),
nodes: nodeReducer,
nodesByType: nodesByTypeReducer,
resolvedNodesCache: require(`./resolved-nodes`),
resolvedNodesCache: resolvedNodesCacheReducer,
nodesTouched: nodesTouchedReducer,
lastAction: lastAction,
flattenedPlugins: require(`./flattened-plugins`),
flattenedPlugins: flattenedPluginsReducer,
config: require(`./config`),
schema: schemaReducer,
pages: pagesReducer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// resolvedNodesCache
module.exports = (state = new Map(), action) => {
import { IGatsbyState, ActionsUnion } from "../types"

export const resolvedNodesCacheReducer = (
state: IGatsbyState["resolvedNodesCache"] = new Map(),
action: ActionsUnion
): IGatsbyState["resolvedNodesCache"] => {
switch (action.type) {
case `DELETE_CACHE`:
case `CREATE_NODE`:
Expand Down
15 changes: 15 additions & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ export type ActionsUnion =
| IReplaceWebpackConfigAction
| ISetPluginStatusAction
| ISetProgramStatusAction
| ISetResolvedNodesAction
| ISetSchemaAction
| ISetSiteFlattenedPluginsAction
| ISetWebpackCompilationHashAction
| ISetWebpackConfigAction
| ITouchNodeAction
Expand Down Expand Up @@ -625,6 +627,19 @@ export interface IDeleteNodesAction {
payload: Identifier[]
}

export interface ISetSiteFlattenedPluginsAction {
type: `SET_SITE_FLATTENED_PLUGINS`
payload: IGatsbyState["flattenedPlugins"]
}

export interface ISetResolvedNodesAction {
type: `SET_RESOLVED_NODES`
payload: {
key: string
nodes: IGatsbyState["resolvedNodesCache"]
}
}

export interface IAddPageDataStatsAction {
type: `ADD_PAGE_DATA_STATS`
payload: {
Expand Down

0 comments on commit 7ad7ac9

Please sign in to comment.