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 React, { PropsWithChildren } from "react"
import * as SC from "./styles" import * as SC from "./styles"
const Container = ({ function Container({
children, children,
...restProps ...restProps
}: PropsWithChildren<{}>): JSX.Element => ( }: PropsWithChildren<{}>): JSX.Element {
<SC.ContainerWrapper {...restProps}>{children}</SC.ContainerWrapper> return <SC.ContainerWrapper {...restProps}>{children}</SC.ContainerWrapper>
) }
export default Container export default Container
+1 -1
View File
@@ -12,7 +12,7 @@ import DocsSidebar from "../DocsSidebar"
import Footer from "../Footer" import Footer from "../Footer"
import * as SC from "./styles" import * as SC from "./styles"
const DocsLayout = ({ children }: PropsWithChildren<{}>) => { function DocsLayout({ children }: PropsWithChildren<{}>) {
const data = useStaticQuery(graphql` const data = useStaticQuery(graphql`
query { query {
site { 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") { if (item.type === "file") {
return ( return (
<SC.PageLink to={item.path} activeClassName="active"> <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 docs = useStaticQuery<IAllDocsQuery>(ALL_DOCS)
const tree = useBuildTree(docs) const tree = useBuildTree(docs)
+7 -7
View File
@@ -7,10 +7,10 @@ import {
IFileQuery, IFileQuery,
} from "./index" } from "./index"
const traverse = ( function traverse(
[head, ...tail]: string[], [head, ...tail]: string[],
basePath = "/docs" basePath = "/docs"
): IFileOrFolder => { ): IFileOrFolder {
const path = basePath + "/" + head const path = basePath + "/" + head
const isFile = !tail.length const isFile = !tail.length
if (isFile) { if (isFile) {
@@ -30,7 +30,7 @@ const traverse = (
} }
} }
const generateFolder = ({ function generateFolder({
title, title,
path, path,
targets, targets,
@@ -38,7 +38,7 @@ const generateFolder = ({
title: IFolder["title"] title: IFolder["title"]
path: IFile["path"] path: IFile["path"]
targets: IFolder[] targets: IFolder[]
}): IFolder => { }): IFolder {
const children = join(R.chain(target => target.children, targets)) const children = join(R.chain(target => target.children, targets))
return { return {
@@ -49,13 +49,13 @@ const generateFolder = ({
} }
} }
const generateFile = ({ function generateFile({
title, title,
path, path,
}: { }: {
title: IFile["title"] title: IFile["title"]
path: IFile["path"] path: IFile["path"]
}): IFile => { }): IFile {
return { return {
title, title,
path, path,
@@ -63,7 +63,7 @@ const generateFile = ({
} }
} }
const join = ([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] => { function join([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] {
if (!head) return [] if (!head) return []
const [similarFs, remaining] = R.partition( const [similarFs, remaining] = R.partition(
+2 -2
View File
@@ -5,10 +5,10 @@ export interface DocsSidebarSectionProps {
readonly title: string readonly title: string
} }
const DocsSidebarSection = ({ function DocsSidebarSection({
title, title,
children, children,
}: PropsWithChildren<DocsSidebarSectionProps>) => { }: PropsWithChildren<DocsSidebarSectionProps>) {
return ( return (
<div> <div>
<SC.SidebarTitle>{title}</SC.SidebarTitle> <SC.SidebarTitle>{title}</SC.SidebarTitle>
+1 -1
View File
@@ -2,7 +2,7 @@ import React from "react"
import * as SC from "./styles" import * as SC from "./styles"
import Container from "../Container" import Container from "../Container"
const Footer = () => { function Footer() {
return ( return (
<SC.FooterWrapper> <SC.FooterWrapper>
<Container> <Container>
+1 -1
View File
@@ -16,7 +16,7 @@ import * as SC from "./styles"
import Scrollbar from "react-perfect-scrollbar" import Scrollbar from "react-perfect-scrollbar"
import "react-perfect-scrollbar/dist/css/styles.css" import "react-perfect-scrollbar/dist/css/styles.css"
const Layout = ({ children }: PropsWithChildren<{}>) => { function Layout({ children }: PropsWithChildren<{}>) {
const data = useStaticQuery(graphql` const data = useStaticQuery(graphql`
query { query {
site { site {
+2 -2
View File
@@ -10,13 +10,13 @@ interface SEOProps {
readonly title: string readonly title: string
} }
const SEO = ({ function SEO({
description, description,
lang = "en", lang = "en",
meta = [], meta = [],
keywords = [], keywords = [],
title, title,
}: SEOProps) => { }: SEOProps) {
const { site } = useStaticQuery( const { site } = useStaticQuery(
graphql` graphql`
query { query {
+1 -1
View File
@@ -11,7 +11,7 @@ function MenuItem({ children, to }: PropsWithChildren<{ to: string }>) {
) )
} }
const Sidebar = () => { function Sidebar() {
return ( return (
<SC.SidebarWrapper> <SC.SidebarWrapper>
<SC.Logo src={logo} /> <SC.Logo src={logo} />
+9 -7
View File
@@ -3,12 +3,14 @@ import React from "react"
import Layout from "../components/Layout" import Layout from "../components/Layout"
import SEO from "../components/SEO" import SEO from "../components/SEO"
const NotFoundPage = () => ( function NotFoundPage() {
<Layout> return (
<SEO title="404: Not found" /> <Layout>
<h1>NOT FOUND</h1> <SEO title="404: Not found" />
<p>You just hit a route that doesn&#39;t exist... the sadness.</p> <h1>NOT FOUND</h1>
</Layout> <p>You just hit a route that doesn&#39;t exist... the sadness.</p>
) </Layout>
)
}
export default NotFoundPage export default NotFoundPage
+8 -6
View File
@@ -3,11 +3,13 @@ import React from "react"
import DocsLayout from "../components/DocsLayout" import DocsLayout from "../components/DocsLayout"
import SEO from "../components/SEO" import SEO from "../components/SEO"
const DocsPage = () => ( function DocsPage() {
<DocsLayout> return (
<SEO title="Docs" /> <DocsLayout>
the docs <SEO title="Docs" />
</DocsLayout> the docs
) </DocsLayout>
)
}
export default DocsPage export default DocsPage
+12 -10
View File
@@ -4,15 +4,17 @@ import { Link } from "gatsby"
import Layout from "../components/Layout" import Layout from "../components/Layout"
import SEO from "../components/SEO" import SEO from "../components/SEO"
const IndexPage = () => ( function IndexPage() {
<Layout> return (
<SEO title="Home" /> <Layout>
<h1>Hi people</h1> <SEO title="Home" />
<p>Welcome to your new Gatsby site.</p> <h1>Hi people</h1>
<p>Now go build something great.</p> <p>Welcome to your new Gatsby site.</p>
<div style={{ maxWidth: `300px`, marginBottom: `1.45rem` }}></div> <p>Now go build something great.</p>
<Link to="/page-2/">Go to page 2</Link> <div style={{ maxWidth: `300px`, marginBottom: `1.45rem` }}></div>
</Layout> <Link to="/page-2/">Go to page 2</Link>
) </Layout>
)
}
export default IndexPage export default IndexPage
+1 -1
View File
@@ -4,7 +4,7 @@ import SEO from "../components/SEO"
import DocsLayout from "../components/DocsLayout" import DocsLayout from "../components/DocsLayout"
// @todo maybe find alternative type for data // @todo maybe find alternative type for data
const LanguagePost = ({ data }: any) => { function LanguagePost({ data }: any) {
const { html, frontmatter } = data.file.post const { html, frontmatter } = data.file.post
console.log(data) console.log(data)
return ( return (