Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove React.createFactory() #534

Merged
merged 1 commit into from Mar 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 16 additions & 21 deletions src/pages/_document.ts → src/pages/_document.tsx
@@ -1,20 +1,13 @@
import { ServerResponse } from 'http';
import { createFactory } from 'react';
import React from 'react';
import { renderToNodeStream } from 'react-dom/server';

import IndexPage from '../pages/index';
import ResultPage from '../pages/result';
import ComparePage from '../pages/compare';
import NotFoundPage from '../pages/404';
import ServerErrorPage from '../pages/500';
import ParseFailurePage from '../pages/parse-failure';

const IndexFactory = createFactory(IndexPage);
const ResultFactory = createFactory(ResultPage);
const CompareFactory = createFactory(ComparePage);
const NotFoundFactory = createFactory(NotFoundPage);
const ServerErrorFactory = createFactory(ServerErrorPage);
const ParseFailureFactory = createFactory(ParseFailurePage);
import Index from './index';
import Result from './result';
import Compare from './compare';
import NotFound from './404';
import ServerError from './500';
import ParseFailure from './parse-failure';

import { getResultProps } from '../page-props/results';
import { getCompareProps } from '../page-props/compare';
Expand Down Expand Up @@ -161,19 +154,21 @@ async function routePage(pathname: string, query: ParsedUrlQuery, tmpDir: string
try {
switch (pathname) {
case pages.index:
return IndexFactory();
return <Index />;
case pages.parseFailure:
return ParseFailureFactory();
return <ParseFailure />;
case pages.result:
return (query.p || '').includes(',')
? CompareFactory(await getCompareProps(query, tmpDir))
: ResultFactory(await getResultProps(query, tmpDir));
return (query.p || '').includes(',') ? (
<Compare {...await getCompareProps(query, tmpDir)} />
) : (
<Result {...await getResultProps(query, tmpDir)} />
);
default:
return NotFoundFactory();
return <NotFound />;
}
} catch (e) {
console.error(`ERROR: ${e.message}`);
return ServerErrorFactory();
return <ServerError />;
}
}

Expand Down