feat: support async layout functions (#1597)

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Marvin Hagemeister
2023-08-08 14:15:02 +02:00
committed by GitHub
co-authored by Asher Gomez
parent 11077227b5
commit 8325225a0d
11 changed files with 277 additions and 65 deletions
@@ -0,0 +1,15 @@
import { LayoutProps, RouteContext } from "$fresh/server.ts";
export default async function AsyncLayout(
req: Request,
ctx: RouteContext,
{ Component }: LayoutProps,
) {
await new Promise((r) => setTimeout(r, 10));
return (
<div class="async-layout">
<p>Async layout</p>
<Component />
</div>
);
}
@@ -0,0 +1,10 @@
import { RouteContext } from "$fresh/server.ts";
export default async function AsyncPage(req: Request, ctx: RouteContext) {
await new Promise((r) => setTimeout(r, 10));
return (
<div class="async-page">
<p>Async page</p>
</div>
);
}
@@ -0,0 +1,14 @@
import { LayoutProps, RouteContext } from "$fresh/server.ts";
import { delay } from "$std/async/mod.ts";
export default async function AsyncSubLayout(
req: Request,
ctx: RouteContext,
{ Component }: LayoutProps,
) {
await delay(10);
return new Response(null, {
status: 307,
headers: { Location: "/async/sub" },
});
}
@@ -0,0 +1,13 @@
import { RouteContext } from "$fresh/server.ts";
export default async function AsyncRedirectPage(
req: Request,
ctx: RouteContext,
) {
await new Promise((r) => setTimeout(r, 10));
return (
<div class="async-sub-page">
<p>Async Redirect page</p>
</div>
);
}
@@ -0,0 +1,15 @@
import { LayoutProps, RouteContext } from "$fresh/server.ts";
export default async function AsyncSubLayout(
req: Request,
ctx: RouteContext,
{ Component }: LayoutProps,
) {
await new Promise((r) => setTimeout(r, 10));
return (
<div class="async-sub-layout">
<p>Async Sub layout</p>
<Component />
</div>
);
}
@@ -0,0 +1,10 @@
import { RouteContext } from "$fresh/server.ts";
export default async function AsyncSubPage(req: Request, ctx: RouteContext) {
await new Promise((r) => setTimeout(r, 10));
return (
<div class="async-sub-page">
<p>Async Sub page</p>
</div>
);
}