Merge pull request #10 from pomber/code-split

Code splitting
This commit is contained in:
Rodrigo Pombo 2019-02-05 20:17:44 -03:00 committed by GitHub
commit e137aac9fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 8 deletions

View File

@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="preconnect" href="https://api.github.com/" crossorigin />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"

View File

@ -1,8 +1,11 @@
import React from "react";
import ReactDOM from "react-dom";
import History from "./history";
function App({ commits }) {
return <History commits={commits} />;
}
export default App;
export function render(commits, root) {
ReactDOM.render(<App commits={commits} />, root);
}

View File

@ -4,6 +4,7 @@
color: rgb(214, 222, 235, 0.8);
padding: 6px;
min-width: 500px;
white-space: nowrap;
}
.comment-box:after,
.comment-box:before {

View File

@ -1,6 +1,3 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./app";
import { getHistory } from "./github";
function getParams() {
@ -24,18 +21,18 @@ const [repo, sha, path] = getParams();
const root = document.getElementById("root");
const message = document.getElementById("message");
if (!repo) {
// show docs
message.innerHTML = `<p>URL should be something like https://github-history.netlify.com/user/repo/commits/master/path/to/file.js</p>`;
} else {
// show loading
message.innerHTML = `<p>Loading <strong>${repo}</strong> <strong>${path}</strong> history...</p>`;
document.title = `GitHub History - ${path.split("/").pop()}`;
getHistory(repo, sha, path)
.then(commits => {
ReactDOM.render(<App commits={commits} />, root);
Promise.all([getHistory(repo, sha, path), import("./app")])
.then(([commits, app]) => {
app.render(commits, root);
})
.catch(error => {
if (error.status === 403) {