From dba8edc4d78924db57ff110cc351fcdf4e60293c Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Wed, 8 Apr 2020 22:00:19 -0500 Subject: [PATCH] address PR feedback --- .../reducers/__tests__/{redirects.js => redirects.ts} | 11 ++++++++--- packages/gatsby/src/redux/reducers/index.js | 3 ++- packages/gatsby/src/redux/reducers/redirects.ts | 5 +---- 3 files changed, 11 insertions(+), 8 deletions(-) rename packages/gatsby/src/redux/reducers/__tests__/{redirects.js => redirects.ts} (89%) diff --git a/packages/gatsby/src/redux/reducers/__tests__/redirects.js b/packages/gatsby/src/redux/reducers/__tests__/redirects.ts similarity index 89% rename from packages/gatsby/src/redux/reducers/__tests__/redirects.js rename to packages/gatsby/src/redux/reducers/__tests__/redirects.ts index 5fbf412e827a3..76323bf7035fc 100644 --- a/packages/gatsby/src/redux/reducers/__tests__/redirects.js +++ b/packages/gatsby/src/redux/reducers/__tests__/redirects.ts @@ -1,9 +1,11 @@ +import { ICreateRedirectAction, IRedirect } from "../../types" + let reducer describe(`redirects`, () => { beforeEach(() => { jest.isolateModules(() => { - reducer = require(`../redirects`).default + reducer = require(`../redirects`).redirectsReducer }) }) it(`lets you redirect to an internal url`, () => { @@ -73,7 +75,10 @@ describe(`redirects`, () => { }) it(`prevents duplicate redirects`, () => { - function createRedirect(fromPath, toPath) { + function createRedirect( + fromPath: string, + toPath: string + ): ICreateRedirectAction { return { type: `CREATE_REDIRECT`, payload: { fromPath, toPath }, @@ -92,7 +97,7 @@ describe(`redirects`, () => { }) it(`allows multiple redirects with same "fromPath" but different options`, () => { - function createRedirect(redirect) { + function createRedirect(redirect: IRedirect): ICreateRedirectAction { return { type: `CREATE_REDIRECT`, payload: redirect, diff --git a/packages/gatsby/src/redux/reducers/index.js b/packages/gatsby/src/redux/reducers/index.js index 642dfbf5d014b..86a4e2509a487 100644 --- a/packages/gatsby/src/redux/reducers/index.js +++ b/packages/gatsby/src/redux/reducers/index.js @@ -1,5 +1,6 @@ const reduxNodes = require(`./nodes`) const lokiNodes = require(`../../db/loki/nodes`).reducer +import { redirectsReducer } from "./redirects" const backend = process.env.GATSBY_DB_NODES || `redux` @@ -59,7 +60,7 @@ module.exports = { jobsV2: require(`./jobsv2`), webpack: require(`./webpack`), webpackCompilationHash: require(`./webpack-compilation-hash`), - redirects: require(`./redirects`).default, + redirects: redirectsReducer, babelrc: require(`./babelrc`), schemaCustomization: require(`./schema-customization`), themes: require(`./themes`), diff --git a/packages/gatsby/src/redux/reducers/redirects.ts b/packages/gatsby/src/redux/reducers/redirects.ts index 6c7408cdde0da..716d0ebe3ed45 100644 --- a/packages/gatsby/src/redux/reducers/redirects.ts +++ b/packages/gatsby/src/redux/reducers/redirects.ts @@ -1,5 +1,4 @@ import _ from "lodash" - import { IGatsbyState, IRedirect, ICreateRedirectAction } from "../types" const redirects = new Map() @@ -23,7 +22,7 @@ function add(redirect: IRedirect): void { samePathRedirects.push(redirect) } -const redirectsReducer = ( +export const redirectsReducer = ( state: IGatsbyState["redirects"] = [], action: ICreateRedirectAction ): IGatsbyState["redirects"] => { @@ -45,5 +44,3 @@ const redirectsReducer = ( return state } } - -export default redirectsReducer