Skip to content

Commit

Permalink
chore(gatsby): Convert page-data-stats reducer to TypeScript (#24082)
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotderek authored May 19, 2020
1 parent 900e6e8 commit bdf0247
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/gatsby/src/redux/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 { pageDataStatsReducer } from "./page-data-stats"
import { componentsReducer } from "./components"
import { componentDataDependenciesReducer } from "./component-data-dependencies"
import { babelrcReducer } from "./babelrc"
Expand Down Expand Up @@ -44,6 +45,6 @@ module.exports = {
themes: themesReducer,
logs: logReducer,
inferenceMetadata: require(`./inference-metadata`),
pageDataStats: require(`./page-data-stats`),
pageDataStats: pageDataStatsReducer,
pageData: pageDataReducer,
}
9 changes: 0 additions & 9 deletions packages/gatsby/src/redux/reducers/page-data-stats.js

This file was deleted.

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

export const pageDataStatsReducer = (
state: IGatsbyState["pageDataStats"] = new Map(),
action: ActionsUnion
): IGatsbyState["pageDataStats"] => {
switch (action.type) {
case `ADD_PAGE_DATA_STATS`:
state.set(action.payload.filePath, action.payload.size)
return state
default:
return state
}
}
9 changes: 9 additions & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export type ActionsUnion =
| ICreateJobV2Action
| IEndJobV2Action
| IRemoveStaleJobV2Action
| IAddPageDataStatsAction
| IRemoveTemplateComponentAction
| ISetBabelPluginAction
| ISetBabelPresetAction
Expand Down Expand Up @@ -587,3 +588,11 @@ export interface IDeleteNodesAction {
type: `DELETE_NODES`
payload: Identifier[]
}

export interface IAddPageDataStatsAction {
type: `ADD_PAGE_DATA_STATS`
payload: {
filePath: SystemPath
size: number
}
}

0 comments on commit bdf0247

Please sign in to comment.