Skip to content

Commit

Permalink
chore(gatsby): convert components to typescript (#24045)
Browse files Browse the repository at this point in the history
* Convert componenets to TS

* Fix import

* Add missing interface

* Address all feedback

* Improve reducer name
  • Loading branch information
Kornil authored May 18, 2020
1 parent a322ef4 commit 6450af2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const normalize = require(`normalize-path`)
const { interpret } = require(`xstate`)
import normalize from "normalize-path"
import { interpret } from "xstate"

import { componentMachine } from "../machines/page-component"
import { IGatsbyState, ActionsUnion } from "../types"

const services = new Map()
let programStatus = `BOOTSTRAPPING`

module.exports = (state = new Map(), action) => {
export const componentsReducer = (
state: IGatsbyState["components"] = new Map(),
action: ActionsUnion
): IGatsbyState["components"] => {
switch (action.type) {
case `DELETE_CACHE`:
return new Map()
Expand Down
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 { componentsReducer } from "./components"
import { componentDataDependenciesReducer } from "./component-data-dependencies"

/**
Expand All @@ -30,7 +31,7 @@ module.exports = {
pages: pagesReducer,
status: statusReducer,
componentDataDependencies: componentDataDependenciesReducer,
components: require(`./components`),
components: componentsReducer,
staticQueryComponents: staticQueryComponentsReducer,
jobs: require(`./jobs`),
jobsV2: jobsV2Reducer,
Expand Down
9 changes: 9 additions & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export type ActionsUnion =
| ICreateJobV2Action
| IEndJobV2Action
| IRemoveStaleJobV2Action
| IRemoveTemplateComponentAction

export interface ICreateJobV2Action {
type: `CREATE_JOB_V2`
Expand Down Expand Up @@ -419,6 +420,7 @@ export interface ICreatePageAction {
type: `CREATE_PAGE`
payload: IGatsbyPage
plugin?: IGatsbyPlugin
contextModified?: boolean
}

export interface ICreateRedirectAction {
Expand Down Expand Up @@ -450,6 +452,13 @@ export interface ISetPageDataAction {
}
}

export interface IRemoveTemplateComponentAction {
type: `REMOVE_TEMPLATE_COMPONENT`
payload: {
componentPath: string
}
}

export interface IDeletePageAction {
type: `DELETE_PAGE`
payload: IGatsbyPage
Expand Down

0 comments on commit 6450af2

Please sign in to comment.