Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bb9228

Browse files
chore(gatsby): Convert flattened-plugins and resolved-nodes to TS (gatsbyjs#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 <[email protected]>
1 parent 503306f commit 4bb9228

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

packages/gatsby/src/redux/reducers/flattened-plugins.js

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { IGatsbyState, ActionsUnion } from "../types"
2+
3+
export const flattenedPluginsReducer = (
4+
state: IGatsbyState["flattenedPlugins"] = [],
5+
action: ActionsUnion
6+
): IGatsbyState["flattenedPlugins"] => {
7+
switch (action.type) {
8+
case `SET_SITE_FLATTENED_PLUGINS`:
9+
return [...action.payload]
10+
11+
default:
12+
return state
13+
}
14+
}

packages/gatsby/src/redux/reducers/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { webpackCompilationHashReducer } from "./webpack-compilation-hash"
1212
import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer"
1313
import { lastAction } from "./last-action"
1414
import { jobsV2Reducer } from "./jobsv2"
15+
import { flattenedPluginsReducer } from "./flattened-plugins"
16+
import { resolvedNodesCacheReducer } from "./resolved-nodes"
1517
import { pageDataStatsReducer } from "./page-data-stats"
1618
import { componentsReducer } from "./components"
1719
import { componentDataDependenciesReducer } from "./component-data-dependencies"
@@ -26,10 +28,10 @@ module.exports = {
2628
program: require(`./program`),
2729
nodes: nodeReducer,
2830
nodesByType: nodesByTypeReducer,
29-
resolvedNodesCache: require(`./resolved-nodes`),
31+
resolvedNodesCache: resolvedNodesCacheReducer,
3032
nodesTouched: nodesTouchedReducer,
3133
lastAction: lastAction,
32-
flattenedPlugins: require(`./flattened-plugins`),
34+
flattenedPlugins: flattenedPluginsReducer,
3335
config: require(`./config`),
3436
schema: schemaReducer,
3537
pages: pagesReducer,

packages/gatsby/src/redux/reducers/resolved-nodes.js renamed to packages/gatsby/src/redux/reducers/resolved-nodes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
// resolvedNodesCache
2-
module.exports = (state = new Map(), action) => {
1+
import { IGatsbyState, ActionsUnion } from "../types"
2+
3+
export const resolvedNodesCacheReducer = (
4+
state: IGatsbyState["resolvedNodesCache"] = new Map(),
5+
action: ActionsUnion
6+
): IGatsbyState["resolvedNodesCache"] => {
37
switch (action.type) {
48
case `DELETE_CACHE`:
59
case `CREATE_NODE`:

packages/gatsby/src/redux/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ export type ActionsUnion =
273273
| IReplaceWebpackConfigAction
274274
| ISetPluginStatusAction
275275
| ISetProgramStatusAction
276+
| ISetResolvedNodesAction
276277
| ISetSchemaAction
278+
| ISetSiteFlattenedPluginsAction
277279
| ISetWebpackCompilationHashAction
278280
| ISetWebpackConfigAction
279281
| ITouchNodeAction
@@ -625,6 +627,19 @@ export interface IDeleteNodesAction {
625627
payload: Identifier[]
626628
}
627629

630+
export interface ISetSiteFlattenedPluginsAction {
631+
type: `SET_SITE_FLATTENED_PLUGINS`
632+
payload: IGatsbyState["flattenedPlugins"]
633+
}
634+
635+
export interface ISetResolvedNodesAction {
636+
type: `SET_RESOLVED_NODES`
637+
payload: {
638+
key: string
639+
nodes: IGatsbyState["resolvedNodesCache"]
640+
}
641+
}
642+
628643
export interface IAddPageDataStatsAction {
629644
type: `ADD_PAGE_DATA_STATS`
630645
payload: {

0 commit comments

Comments
 (0)