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 static-query-components reducer to TypeScript #23475

Merged
merged 1 commit into from
Apr 27, 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
@@ -1,6 +1,7 @@
const reduxNodes = require(`./nodes`)
const lokiNodes = require(`../../db/loki/nodes`).reducer
import { redirectsReducer } from "./redirects"
import { staticQueryComponentsReducer } from "./static-query-components"
import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer"

const backend = process.env.GATSBY_DB_NODES || `redux`
Expand Down Expand Up @@ -56,7 +57,7 @@ module.exports = {
status: require(`./status`),
componentDataDependencies: require(`./component-data-dependencies`),
components: require(`./components`),
staticQueryComponents: require(`./static-query-components`),
staticQueryComponents: staticQueryComponentsReducer,
jobs: require(`./jobs`),
jobsV2: require(`./jobsv2`),
webpack: require(`./webpack`),
Expand Down
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 staticQueryComponentsReducer = (
state: IGatsbyState["staticQueryComponents"] = new Map(),
action: ActionsUnion
): IGatsbyState["staticQueryComponents"] => {
switch (action.type) {
case `DELETE_CACHE`:
return new Map()
Expand Down
34 changes: 26 additions & 8 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export interface IGatsbyPluginContext {
[key: string]: (...args: any[]) => any
}

export interface IGatsbyStaticQueryComponents {
name: string
componentPath: SystemPath
id: Identifier
query: string
hash: string
}

type GatsbyNodes = Map<string, IGatsbyNode>

export interface IGatsbyState {
Expand Down Expand Up @@ -139,14 +147,8 @@ export interface IGatsbyState {
}
>
staticQueryComponents: Map<
number,
{
name: string
componentPath: SystemPath
id: Identifier
query: string
hash: string
}
IGatsbyStaticQueryComponents["id"],
IGatsbyStaticQueryComponents
>
// @deprecated
jobs: {
Expand Down Expand Up @@ -207,6 +209,7 @@ export interface ICachedReduxState {

export type ActionsUnion =
| ICreatePageDependencyAction
| IDeleteCacheAction
| IDeleteComponentDependenciesAction
| IReplaceComponentQueryAction
| IReplaceStaticQueryAction
Expand All @@ -220,6 +223,7 @@ export type ActionsUnion =
| ICreateTypes
| ICreateFieldExtension
| IPrintTypeDefinitions
| IRemoveStaticQuery

export interface ICreatePageDependencyAction {
type: `CREATE_COMPONENT_DEPENDENCY`
Expand Down Expand Up @@ -359,3 +363,17 @@ export interface ICreateRedirectAction {
type: `CREATE_REDIRECT`
payload: IRedirect
}

export interface IDeleteCacheAction {
type: `DELETE_CACHE`
}

export interface IReplaceStaticQueryAction {
type: `REPLACE_STATIC_QUERY`
payload: IGatsbyStaticQueryComponents
}

export interface IRemoveStaticQuery {
type: `REMOVE_STATIC_QUERY`
payload: IGatsbyStaticQueryComponents["id"]
}