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 pageData reducer to TypeScript #23738

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -4,6 +4,7 @@ import { redirectsReducer } from "./redirects"
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 { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer"
Expand Down Expand Up @@ -74,5 +75,5 @@ module.exports = {
logs: logReducer,
inferenceMetadata: require(`./inference-metadata`),
pageDataStats: require(`./page-data-stats`),
pageData: require(`./page-data`),
pageData: pageDataReducer,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = (state = new Map(), action) => {
import { ActionsUnion, IGatsbyState } from "../types"

export const pageDataReducer = (
state: IGatsbyState["pageData"] = new Map(),
action: ActionsUnion
): IGatsbyState["pageData"] => {
switch (action.type) {
case `DELETE_CACHE`:
return new Map()
Expand Down
19 changes: 18 additions & 1 deletion packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export interface IGatsbyState {
}
}
pageDataStats: Map<SystemPath, number>
pageData: any
pageData: Map<Identifier, string>
}

export interface ICachedReduxState {
Expand Down Expand Up @@ -243,6 +243,8 @@ export type ActionsUnion =
| ISetWebpackCompilationHashAction
| ISetWebpackConfigAction
| IUpdatePluginsHashAction
| IRemovePageDataAction
| ISetPageDataAction

export interface ICreatePageDependencyAction {
type: `CREATE_COMPONENT_DEPENDENCY`
Expand Down Expand Up @@ -392,6 +394,21 @@ export interface IDeleteCacheAction {
type: `DELETE_CACHE`
}

export interface IRemovePageDataAction {
type: `REMOVE_PAGE_DATA`
payload: {
id: Identifier
}
}

export interface ISetPageDataAction {
type: `SET_PAGE_DATA`
payload: {
id: Identifier
resultHash: string
}
}

export interface IReplaceStaticQueryAction {
type: `REPLACE_STATIC_QUERY`
payload: IGatsbyStaticQueryComponents
Expand Down