Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
blainekasten committed Apr 9, 2020
1 parent cae80d5 commit dba8edc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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`, () => {
Expand Down Expand Up @@ -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 },
Expand All @@ -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,
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
@@ -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`

Expand Down Expand Up @@ -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`),
Expand Down
5 changes: 1 addition & 4 deletions packages/gatsby/src/redux/reducers/redirects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from "lodash"

import { IGatsbyState, IRedirect, ICreateRedirectAction } from "../types"

const redirects = new Map<string, IRedirect[]>()
Expand All @@ -23,7 +22,7 @@ function add(redirect: IRedirect): void {
samePathRedirects.push(redirect)
}

const redirectsReducer = (
export const redirectsReducer = (
state: IGatsbyState["redirects"] = [],
action: ICreateRedirectAction
): IGatsbyState["redirects"] => {
Expand All @@ -45,5 +44,3 @@ const redirectsReducer = (
return state
}
}

export default redirectsReducer

0 comments on commit dba8edc

Please sign in to comment.