-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from nyaomaru/deno-study-3
stydy: island and middleware
- Loading branch information
Showing
5 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { JSX } from "preact"; | ||
|
||
export function Card(props: JSX.HTMLAttributes<HTMLButtonElement>) { | ||
return ( | ||
<div class="max-w-sm rounded overflow-hidden shadow-lg bg-white border-gray-400 "> | ||
<div class="px-6 py-4"> | ||
<div class="font-bold text-xl mb-2">{props.title}</div> | ||
{props.children} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
import type { Signal } from "@preact/signals"; | ||
import { useSignal } from "@preact/signals"; | ||
import { ComponentChildren } from "preact"; | ||
import { Button } from "../components/Button.tsx"; | ||
import { Card } from "../components/Card.tsx"; | ||
|
||
interface CounterProps { | ||
count: Signal<number>; | ||
interface Props { | ||
children: ComponentChildren; | ||
} | ||
|
||
export default function Counter(props: CounterProps) { | ||
export default function MyIsland({ children }: Props) { | ||
const count = useSignal(0); | ||
|
||
return ( | ||
<div class="flex gap-8 py-6"> | ||
<Button onClick={() => props.count.value -= 1}>-1</Button> | ||
<p class="text-3xl tabular-nums">{props.count}</p> | ||
<Button onClick={() => props.count.value += 1}>+1</Button> | ||
</div> | ||
<Card title={"Counter"}> | ||
<div class="flex gap-8"> | ||
<Button onClick={() => count.value -= 1}>-</Button> | ||
<p class="text-3xl tabular-nums">{count}</p> | ||
<Button onClick={() => (count.value += 1)}>+</Button> | ||
</div> | ||
{children} | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FreshContext } from "$fresh/server.ts"; | ||
|
||
interface State { | ||
data: string; | ||
} | ||
|
||
export async function handler( | ||
req: Request, | ||
ctx: FreshContext<State>, | ||
) { | ||
ctx.state.data = "myData"; | ||
const resp = await ctx.next(); | ||
resp.headers.set("server", "fresh server"); | ||
return resp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters