Skip to content

Commit 3c17fc1

Browse files
committed
get framework together
1 parent e041e90 commit 3c17fc1

30 files changed

+3586
-0
lines changed

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/js-collection-benchmarks.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLinters/eslint.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/prettier.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
18+
19+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
20+
21+
## Learn More
22+
23+
To learn more about Next.js, take a look at the following resources:
24+
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29+
30+
## Deploy on Vercel
31+
32+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33+
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

Taskfile.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3'
2+
3+
tasks:
4+
dev:
5+
desc: "Run on localhost:3000"
6+
cmds:
7+
- pnpm dev

app/_util/MergeReducer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const MergeReducer = <T extends {}>(
2+
state: Readonly<T>,
3+
action: Partial<Readonly<T>>,
4+
): T => ({ ...state, ...action })

app/_util/PageBase.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use client"
2+
3+
import { PropsWithChildren, ReactNode } from "react"
4+
import { usePathname } from "next/navigation"
5+
6+
export const PageBase = ({ children }: PropsWithChildren) => {
7+
return (
8+
<div className="flex flex-col min-h-screen">
9+
<NavBar />
10+
<main className="flex-grow flex flex-col">{children}</main>
11+
</div>
12+
)
13+
}
14+
15+
export const NavBar = () => (
16+
<header className="w-screen flex flex-row justify-between text-xl border-b-2 border-black dark:border-white">
17+
<h1 className="justify-self-start font-bold bg-amber-300 dark:bg-amber-900 px-2 py-1">
18+
JS Collection Benchmarks
19+
</h1>
20+
<Nav route="bench">Benchmarks</Nav>
21+
<Nav route="next">Next.js Guide</Nav>
22+
</header>
23+
)
24+
25+
const Nav = ({ route, children }: { route: string; children: ReactNode }) => {
26+
const path = usePathname()
27+
const isCurrent = path.toLowerCase().indexOf(route) >= 0
28+
return isCurrent ? (
29+
<nav className="flex-grow text-center bg-green-300 dark:bg-green-700 px-2 py-1">
30+
{children}
31+
</nav>
32+
) : (
33+
<a
34+
href={`/${route}`}
35+
className="flex-grow text-center bg-green-300 dark:bg-green-900 px-2 py-1"
36+
>
37+
{children}
38+
</a>
39+
)
40+
}

app/bench/BenchMarks.tsx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use client"
2+
3+
import {
4+
Dispatch,
5+
FormEvent,
6+
Fragment,
7+
useCallback,
8+
useEffect,
9+
useReducer,
10+
} from "react"
11+
import { MergeReducer } from "@/app/_util/MergeReducer"
12+
import { capitalCase, headerCase } from "change-case"
13+
14+
interface BenchConfig {
15+
collectionSize: number // how big is the collection we're operating on
16+
iterations: number // how many times we loop through
17+
mutationFraction: number // between 0 and 1 — the fraction of items changed on each loop
18+
}
19+
20+
const BenchInputs: ReadonlyArray<keyof BenchConfig> = [
21+
"collectionSize",
22+
"iterations",
23+
"mutationFraction",
24+
]
25+
26+
interface BenchState extends BenchConfig {
27+
running?: boolean
28+
}
29+
30+
const INITIAL_BENCH_STATE: BenchState = {
31+
collectionSize: 1000,
32+
iterations: 1000,
33+
mutationFraction: 0.1,
34+
}
35+
36+
export const BenchMarks = () => {
37+
const [state, dispatch] = useReducer<typeof MergeReducer<BenchState>>(
38+
MergeReducer,
39+
INITIAL_BENCH_STATE,
40+
)
41+
const handleReset = useCallback(() => dispatch(INITIAL_BENCH_STATE), [])
42+
const handleStart = useCallback((e: FormEvent) => {
43+
dispatch({ running: true })
44+
e.preventDefault()
45+
}, [])
46+
const handleCancel = useCallback((e: FormEvent) => {
47+
dispatch({ running: false })
48+
e.preventDefault()
49+
}, [])
50+
const { running } = state
51+
useEffect(() => {
52+
if (state.running) console.log("start")
53+
}, [state.running])
54+
return (
55+
<form
56+
onSubmit={running ? handleCancel : handleStart}
57+
action="#"
58+
className="flex-grow grid content-center justify-items-center items-center gap-3 grid-cols-2"
59+
>
60+
{BenchInputs.map((name) => (
61+
<Fragment key={name}>
62+
<label htmlFor={name} className="justify-self-end">
63+
{capitalCase(name)}
64+
</label>
65+
<input
66+
name={name}
67+
type="number"
68+
className="input justify-self-start"
69+
onChange={(e) =>
70+
dispatch({
71+
[name]: fix(Number(e.target.value), name),
72+
})
73+
}
74+
value={state[name]}
75+
disabled={state.running}
76+
/>
77+
</Fragment>
78+
))}
79+
<button className="btn col-span-2">
80+
{running ? "Cancel" : "Start"}
81+
</button>
82+
</form>
83+
)
84+
}
85+
86+
const fix = (n: number, name: keyof BenchConfig): number =>
87+
name === "mutationFraction"
88+
? Math.min(Math.max(0, n), 1)
89+
: Math.max(0, Math.floor(n))

app/bench/page.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NavBar, PageBase } from "@/app/_util/PageBase"
2+
import { BenchMarks } from "@/app/bench/BenchMarks"
3+
4+
const Benchmarks = () => {
5+
return (
6+
<PageBase>
7+
<BenchMarks />
8+
</PageBase>
9+
)
10+
}
11+
12+
export default Benchmarks

app/favicon.ico

25.3 KB
Binary file not shown.

app/globals.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
:root {
6+
--foreground-rgb: 0, 0, 0;
7+
--background-start-rgb: 214, 219, 220;
8+
--background-end-rgb: 255, 255, 255;
9+
}
10+
11+
@media (prefers-color-scheme: dark) {
12+
:root {
13+
--foreground-rgb: 255, 255, 255;
14+
--background-start-rgb: 0, 0, 0;
15+
--background-end-rgb: 0, 0, 0;
16+
}
17+
}
18+
19+
body {
20+
color: rgb(var(--foreground-rgb));
21+
background: linear-gradient(
22+
to bottom,
23+
transparent,
24+
rgb(var(--background-end-rgb))
25+
)
26+
rgb(var(--background-start-rgb));
27+
}

0 commit comments

Comments
 (0)