refact: prefer function over lambdas

This commit is contained in:
Jean-Philippe Sirois
2019-07-27 17:54:51 -04:00
parent f7f66a3071
commit 90fb9b1888
13 changed files with 51 additions and 45 deletions
+4 -4
View File
@@ -1,11 +1,11 @@
import React, { PropsWithChildren } from "react"
import * as SC from "./styles"
const Container = ({
function Container({
children,
...restProps
}: PropsWithChildren<{}>): JSX.Element => (
<SC.ContainerWrapper {...restProps}>{children}</SC.ContainerWrapper>
)
}: PropsWithChildren<{}>): JSX.Element {
return <SC.ContainerWrapper {...restProps}>{children}</SC.ContainerWrapper>
}
export default Container
+1 -1
View File
@@ -12,7 +12,7 @@ import DocsSidebar from "../DocsSidebar"
import Footer from "../Footer"
import * as SC from "./styles"
const DocsLayout = ({ children }: PropsWithChildren<{}>) => {
function DocsLayout({ children }: PropsWithChildren<{}>) {
const data = useStaticQuery(graphql`
query {
site {
+2 -2
View File
@@ -55,7 +55,7 @@ const ALL_DOCS = graphql`
}
`
const plantTree = (item: IFileOrFolder) => {
function plantTree(item: IFileOrFolder) {
if (item.type === "file") {
return (
<SC.PageLink to={item.path} activeClassName="active">
@@ -84,7 +84,7 @@ function Folder({ item }: { item: IFolder }) {
)
}
const DocsSidebar = () => {
function DocsSidebar() {
const docs = useStaticQuery<IAllDocsQuery>(ALL_DOCS)
const tree = useBuildTree(docs)
+7 -7
View File
@@ -7,10 +7,10 @@ import {
IFileQuery,
} from "./index"
const traverse = (
function traverse(
[head, ...tail]: string[],
basePath = "/docs"
): IFileOrFolder => {
): IFileOrFolder {
const path = basePath + "/" + head
const isFile = !tail.length
if (isFile) {
@@ -30,7 +30,7 @@ const traverse = (
}
}
const generateFolder = ({
function generateFolder({
title,
path,
targets,
@@ -38,7 +38,7 @@ const generateFolder = ({
title: IFolder["title"]
path: IFile["path"]
targets: IFolder[]
}): IFolder => {
}): IFolder {
const children = join(R.chain(target => target.children, targets))
return {
@@ -49,13 +49,13 @@ const generateFolder = ({
}
}
const generateFile = ({
function generateFile({
title,
path,
}: {
title: IFile["title"]
path: IFile["path"]
}): IFile => {
}): IFile {
return {
title,
path,
@@ -63,7 +63,7 @@ const generateFile = ({
}
}
const join = ([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] => {
function join([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] {
if (!head) return []
const [similarFs, remaining] = R.partition(
+2 -2
View File
@@ -5,10 +5,10 @@ export interface DocsSidebarSectionProps {
readonly title: string
}
const DocsSidebarSection = ({
function DocsSidebarSection({
title,
children,
}: PropsWithChildren<DocsSidebarSectionProps>) => {
}: PropsWithChildren<DocsSidebarSectionProps>) {
return (
<div>
<SC.SidebarTitle>{title}</SC.SidebarTitle>
+1 -1
View File
@@ -2,7 +2,7 @@ import React from "react"
import * as SC from "./styles"
import Container from "../Container"
const Footer = () => {
function Footer() {
return (
<SC.FooterWrapper>
<Container>
+1 -1
View File
@@ -16,7 +16,7 @@ import * as SC from "./styles"
import Scrollbar from "react-perfect-scrollbar"
import "react-perfect-scrollbar/dist/css/styles.css"
const Layout = ({ children }: PropsWithChildren<{}>) => {
function Layout({ children }: PropsWithChildren<{}>) {
const data = useStaticQuery(graphql`
query {
site {
+2 -2
View File
@@ -10,13 +10,13 @@ interface SEOProps {
readonly title: string
}
const SEO = ({
function SEO({
description,
lang = "en",
meta = [],
keywords = [],
title,
}: SEOProps) => {
}: SEOProps) {
const { site } = useStaticQuery(
graphql`
query {
+1 -1
View File
@@ -11,7 +11,7 @@ function MenuItem({ children, to }: PropsWithChildren<{ to: string }>) {
)
}
const Sidebar = () => {
function Sidebar() {
return (
<SC.SidebarWrapper>
<SC.Logo src={logo} />