feat: a new "island" based architechture (#97)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
export * from "../runtime.ts";
|
||||
import { IS_BROWSER } from "../runtime.ts";
|
||||
import { setup, tw } from "https://esm.sh/twind@0.16.16";
|
||||
export { setup, tw };
|
||||
if (IS_BROWSER) {
|
||||
setup({});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/** @jsx h */
|
||||
|
||||
import { h, tw } from "../deps.ts";
|
||||
import { h, tw } from "../client_deps.ts";
|
||||
|
||||
export function RoundedButton(props: h.JSX.HTMLAttributes<HTMLButtonElement>) {
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** @jsx h */
|
||||
|
||||
import { h, tw } from "../deps.ts";
|
||||
import { h, tw } from "../client_deps.ts";
|
||||
|
||||
export function IconMinus() {
|
||||
return (
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
/// <reference lib="deno.unstable" />
|
||||
|
||||
export * from "../runtime.ts";
|
||||
import { IS_BROWSER } from "../runtime.ts";
|
||||
import { setup, tw } from "https://esm.sh/twind";
|
||||
export { setup, tw };
|
||||
if (IS_BROWSER) {
|
||||
setup({});
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// DO NOT EDIT. This file is generated by `fresh`.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// To update this file, run `fresh routes`.
|
||||
|
||||
import * as $0 from "./routes/_render.ts";
|
||||
import * as $1 from "./routes/index.tsx";
|
||||
import * as $$0 from "./islands/Counter.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/_render.ts": $0,
|
||||
"./routes/index.tsx": $1,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$0,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,34 @@
|
||||
/** @jsx h */
|
||||
import { h, IS_BROWSER, tw, useState } from "../client_deps.ts";
|
||||
import { RoundedButton } from "../components/Button.tsx";
|
||||
import { IconMinus, IconPlus } from "../components/Icons.tsx";
|
||||
|
||||
interface CounterProps {
|
||||
start: number;
|
||||
}
|
||||
|
||||
export default function Counter(props: CounterProps) {
|
||||
const [count, setCount] = useState(props.start);
|
||||
return (
|
||||
<div
|
||||
class={tw
|
||||
`bg-gray-100 p-4 border border-gray-200 flex items-center justify-around`}
|
||||
>
|
||||
<RoundedButton
|
||||
title="Subtract 1"
|
||||
onClick={() => setCount(count - 1)}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
<IconMinus />
|
||||
</RoundedButton>
|
||||
<div class={tw`text-3xl`}>{count}</div>
|
||||
<RoundedButton
|
||||
title="Add 1"
|
||||
onClick={() => setCount(count + 1)}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
<IconPlus />
|
||||
</RoundedButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
import { start } from "../server.ts";
|
||||
import routes from "./routes.gen.ts";
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
/// <reference lib="deno.unstable" />
|
||||
|
||||
import { start } from "./server_deps.ts";
|
||||
import routes from "./fresh.gen.ts";
|
||||
|
||||
await start(routes);
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// DO NOT EDIT. This file is generated by `fresh`.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// To update this file, run `fresh routes`.
|
||||
|
||||
import * as $0 from "./pages/index.tsx";
|
||||
import * as $1 from "./pages/_render.ts";
|
||||
|
||||
const routes = {
|
||||
pages: {
|
||||
"./pages/index.tsx": $0,
|
||||
"./pages/_render.ts": $1,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default routes;
|
||||
@@ -1,8 +1,7 @@
|
||||
// This module adds twind support.
|
||||
|
||||
import { virtualSheet } from "https://esm.sh/twind/sheets";
|
||||
import { setup } from "../deps.ts";
|
||||
import { RenderContext, RenderFn } from "../server_deps.ts";
|
||||
import { setup } from "../client_deps.ts";
|
||||
import { RenderContext, RenderFn, virtualSheet } from "../server_deps.ts";
|
||||
|
||||
const sheet = virtualSheet();
|
||||
sheet.reset();
|
||||
@@ -1,18 +1,24 @@
|
||||
/** @jsx h */
|
||||
/** @jsxFrag Fragment */
|
||||
|
||||
import { Fragment, h, Head, tw } from "../deps.ts";
|
||||
import { Fragment, h, Head, tw } from "../client_deps.ts";
|
||||
import Counter from "../islands/Counter.tsx";
|
||||
|
||||
export default function MainPage() {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>fresh - The next-gen web framework.</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="The next-gen web framework. Just in time edge rendering, island based interactivity, and no configuration TypeScript support."
|
||||
/>
|
||||
</Head>
|
||||
<Hero />
|
||||
<NavigationBar active="/" />
|
||||
<Intro />
|
||||
<GettingStarted />
|
||||
<Example />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -28,9 +34,9 @@ function Hero() {
|
||||
<h1 class={title}>
|
||||
fresh
|
||||
</h1>
|
||||
<h3 class={subtitle}>
|
||||
<p class={subtitle}>
|
||||
The next-gen web framework.
|
||||
</h3>
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -79,7 +85,7 @@ function Intro() {
|
||||
<b>Just-in-time rendering</b> on the edge.
|
||||
</li>
|
||||
<li>
|
||||
<b>Selective client hydration</b> for maximum interactivity.
|
||||
<b>Island based client hydration</b> for maximum interactivity.
|
||||
</li>
|
||||
<li>
|
||||
<b>Zero runtime overhead</b>: no JS is shipped to the client by
|
||||
@@ -106,14 +112,14 @@ function Intro() {
|
||||
function GettingStarted() {
|
||||
return (
|
||||
<section class={tw`max-w-screen-sm mx-auto my-16 px(4 sm:6 md:8)`}>
|
||||
<h3 id="getting-started" class={tw`text(xl gray-600) font-bold`}>
|
||||
<h2 id="getting-started" class={tw`text(xl gray-600) font-bold`}>
|
||||
<a href="#getting-started" class={tw`hover:underline`}>
|
||||
Getting started
|
||||
</a>
|
||||
</h3>
|
||||
</h2>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
To get started, make sure you have the{" "}
|
||||
<a href="https://deno.land" class={tw`text-blue-500 hover:underline`}>
|
||||
<a href="https://deno.land" class={tw`text-blue-600 hover:underline`}>
|
||||
Deno CLI
|
||||
</a>{" "}
|
||||
installed.
|
||||
@@ -143,7 +149,7 @@ function GettingStarted() {
|
||||
You can now open{" "}
|
||||
<a
|
||||
href="http://localhost:8000"
|
||||
class={tw`text-blue-500 hover:underline`}
|
||||
class={tw`text-blue-600 hover:underline`}
|
||||
>
|
||||
http://localhost:8000
|
||||
</a>{" "}
|
||||
@@ -151,7 +157,40 @@ function GettingStarted() {
|
||||
</p>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
A more in-depth getting started guide is available in{" "}
|
||||
<a href="/docs" class={tw`text-blue-500 hover:underline`}>the docs</a>.
|
||||
<a href="/docs" class={tw`text-blue-600 hover:underline`}>the docs</a>.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
const timeFmt = new Intl.DateTimeFormat("en-US", {
|
||||
timeStyle: "long",
|
||||
hour12: false,
|
||||
});
|
||||
|
||||
function Example() {
|
||||
return (
|
||||
<section
|
||||
class={tw`max-w-screen-sm mx-auto my-16 px(4 sm:6 md:8)`}
|
||||
>
|
||||
<h2 id="example" class={tw`text(xl gray-600) font-bold`}>
|
||||
<a href="#example" class={tw`hover:underline`}>
|
||||
Example
|
||||
</a>
|
||||
</h2>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
This text is being server side rendered on the fly. It was rendered at
|
||||
{" "}
|
||||
{timeFmt.format(new Date())}.
|
||||
</p>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
The counter below was rendered on the server with a starting value of 3,
|
||||
and was then hydrated on the client to provide interactivity. Try out
|
||||
the buttons!
|
||||
</p>
|
||||
<Counter start={3} />
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
Only the JS required to render that counter is sent to the client.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
@@ -1 +1,2 @@
|
||||
export * from "../server.ts";
|
||||
export { virtualSheet } from "https://esm.sh/twind@0.16.16/sheets";
|
||||
|
||||
Reference in New Issue
Block a user