chore: update types in tests, init, update (#2122)
Of particular note is the change to
`tests/fixture_plugin/routes/test.tsx`. Note how I do this:
```diff
- async GET(_req, ctx: HandlerContext<unknown, { test: string }>) {
+ async GET(_req, ctx: FreshContext<{ test: string }, unknown>) {
```
I find it strange and confusing that the order of the type parameters
has "changed". This makes it impossible to do a simple search and
replace, because people now have to change order as well.
Most of the types have been declared as `<T, S>`, i.e. data before
state:
* `PageProps<T = any, S = Record<string, unknown>>`
* `RouteContext<T = any, S = Record<string, unknown>>`
* `Handler<T = any, State = Record<string, unknown>>`
* `Handlers<T = any, State = Record<string, unknown>> `
* `AsyncRoute<T = any, S = Record<string, unknown>>`
* `PageComponent<T = any, S = Record<string, unknown>> `
* `AsyncLayout<T = any, S = Record<string, unknown>>`
And then `FreshContext` comes around like
```
export interface FreshContext<
State = Record<string, unknown>,
// deno-lint-ignore no-explicit-any
Data = any,
NotFoundData = Data,
>
```
and switches it all up.
Not a huge issue, but just something to be aware of that others might
report.
This commit is contained in:
@@ -273,7 +273,7 @@ await Deno.writeTextFile(
|
|||||||
ROUTES_GREET_TSX,
|
ROUTES_GREET_TSX,
|
||||||
);
|
);
|
||||||
|
|
||||||
const ROUTES_API_JOKE_TS = `import { HandlerContext } from "$fresh/server.ts";
|
const ROUTES_API_JOKE_TS = `import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
// Jokes courtesy of https://punsandoneliners.com/randomness/programmer-jokes/
|
// Jokes courtesy of https://punsandoneliners.com/randomness/programmer-jokes/
|
||||||
const JOKES = [
|
const JOKES = [
|
||||||
@@ -289,7 +289,7 @@ const JOKES = [
|
|||||||
"An SEO expert walked into a bar, pub, inn, tavern, hostelry, public house.",
|
"An SEO expert walked into a bar, pub, inn, tavern, hostelry, public house.",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const handler = (_req: Request, _ctx: HandlerContext): Response => {
|
export const handler = (_req: Request, _ctx: FreshContext): Response => {
|
||||||
const randomIndex = Math.floor(Math.random() * JOKES.length);
|
const randomIndex = Math.floor(Math.random() * JOKES.length);
|
||||||
const body = JOKES[randomIndex];
|
const body = JOKES[randomIndex];
|
||||||
return new Response(body);
|
return new Response(body);
|
||||||
@@ -443,8 +443,8 @@ html {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const APP_WRAPPER = `import { type AppProps } from "$fresh/server.ts";
|
const APP_WRAPPER = `import { type PageProps } from "$fresh/server.ts";
|
||||||
export default function App({ Component }: AppProps) {
|
export default function App({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
+3
-12
@@ -1,16 +1,7 @@
|
|||||||
import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
|
import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
|
||||||
import {
|
import { BaseRoute, FreshContext } from "./types.ts";
|
||||||
BaseRoute,
|
|
||||||
ErrorHandlerContext,
|
|
||||||
FreshContext,
|
|
||||||
ServeHandlerInfo,
|
|
||||||
} from "./types.ts";
|
|
||||||
import { isIdentifierChar, isIdentifierStart } from "./init_safe_deps.ts";
|
import { isIdentifierChar, isIdentifierStart } from "./init_safe_deps.ts";
|
||||||
|
|
||||||
type HandlerContext<T = unknown> = T & ServeHandlerInfo & {
|
|
||||||
isPartial: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Handler<T = Record<string, unknown>> = (
|
export type Handler<T = Record<string, unknown>> = (
|
||||||
req: Request,
|
req: Request,
|
||||||
ctx: FreshContext<T>,
|
ctx: FreshContext<T>,
|
||||||
@@ -91,7 +82,7 @@ export function defaultOtherHandler(_req: Request): Response {
|
|||||||
|
|
||||||
export function defaultErrorHandler(
|
export function defaultErrorHandler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
_ctx: ErrorHandlerContext,
|
_ctx: FreshContext,
|
||||||
err: unknown,
|
err: unknown,
|
||||||
): Response {
|
): Response {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -103,7 +94,7 @@ export function defaultErrorHandler(
|
|||||||
|
|
||||||
export function defaultUnknownMethodHandler(
|
export function defaultUnknownMethodHandler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
_ctx: HandlerContext,
|
_ctx: FreshContext,
|
||||||
knownMethods: KnownMethod[],
|
knownMethods: KnownMethod[],
|
||||||
): Response {
|
): Response {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
// handlers are supposed to return something, so in order to make type checker on the manifest happy, we'll use any to escape it
|
// handlers are supposed to return something, so in order to make type checker on the manifest happy, we'll use any to escape it
|
||||||
export function handler(
|
export function handler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
_ctx: MiddlewareHandlerContext,
|
_ctx: FreshContext,
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
): any {
|
): any {
|
||||||
throw new Deno.errors.NotFound();
|
throw new Deno.errors.NotFound();
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { UnknownPageProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
type Data = { hello: string };
|
type Data = { hello: string };
|
||||||
type State = { root: string };
|
type State = { root: string };
|
||||||
|
|
||||||
export default function NotFoundPage(
|
export default function NotFoundPage(
|
||||||
{ data, state, url }: UnknownPageProps<Data | undefined, State>,
|
{ data, state, url }: PageProps<Data | undefined, State>,
|
||||||
) {
|
) {
|
||||||
// Checks that we have the correct type for state
|
// Checks that we have the correct type for state
|
||||||
state.root satisfies string;
|
state.root satisfies string;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ErrorPageProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Error500Page({ error }: ErrorPageProps) {
|
export default function Error500Page({ error }: PageProps) {
|
||||||
return <p>500 internal error: {(error as Error).message}</p>;
|
return <p>500 internal error: {(error as Error).message}</p>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Head } from "$fresh/runtime.ts";
|
import { Head } from "$fresh/runtime.ts";
|
||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export type TestState = {
|
export type TestState = {
|
||||||
root: string;
|
root: string;
|
||||||
stateInProps: string;
|
stateInProps: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function App(props: AppProps<unknown, TestState>) {
|
export default function App(props: PageProps<unknown, TestState>) {
|
||||||
const statefulValue = props.state?.root === "root_mw"
|
const statefulValue = props.state?.root === "root_mw"
|
||||||
? "The freshest framework!"
|
? "The freshest framework!"
|
||||||
: "";
|
: "";
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { HandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return <div>This is HTML</div>;
|
return <div>This is HTML</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handler = {
|
export const handler = {
|
||||||
GET(req: Request, { render }: HandlerContext) {
|
GET(req: Request, { render }: FreshContext) {
|
||||||
if (req.headers.get("accept")?.includes("text/html")) {
|
if (req.headers.get("accept")?.includes("text/html")) {
|
||||||
return render();
|
return render();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(_req: Request, ctx: FreshContext) {
|
||||||
ctx.state.layer1 = "layer1_mw";
|
ctx.state.layer1 = "layer1_mw";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
resp.headers.set("server", "fresh test server layer1");
|
resp.headers.set("server", "fresh test server layer1");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(_req: Request, ctx: FreshContext) {
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
resp.headers.set("middlewareParams_inner", JSON.stringify(ctx.params));
|
resp.headers.set("middlewareParams_inner", JSON.stringify(ctx.params));
|
||||||
return resp;
|
return resp;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(_req: Request, ctx: FreshContext) {
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
resp.headers.set("middlewareParams_outer", JSON.stringify(ctx.params));
|
resp.headers.set("middlewareParams_outer", JSON.stringify(ctx.params));
|
||||||
return resp;
|
return resp;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
root: string;
|
root: string;
|
||||||
@@ -8,7 +8,7 @@ interface State {
|
|||||||
|
|
||||||
export async function handler(
|
export async function handler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<State>,
|
ctx: FreshContext<State>,
|
||||||
) {
|
) {
|
||||||
ctx.state.layer2 = "layer2_mw";
|
ctx.state.layer2 = "layer2_mw";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(_req: Request, ctx: FreshContext) {
|
||||||
ctx.state.layer3 = "layer3_mw";
|
ctx.state.layer3 = "layer3_mw";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
resp.headers.set("server", "fresh test server layer3");
|
resp.headers.set("server", "fresh test server layer3");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(_req: Request, ctx: FreshContext) {
|
||||||
ctx.state.middlewareNestingOrder += "3";
|
ctx.state.middlewareNestingOrder += "3";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
return resp;
|
return resp;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(_req: Request, ctx: FreshContext) {
|
||||||
ctx.state.middlewareNestingOrder += "2";
|
ctx.state.middlewareNestingOrder += "2";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
return resp;
|
return resp;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(_req: Request, ctx: FreshContext) {
|
||||||
ctx.state.middlewareNestingOrder = "1";
|
ctx.state.middlewareNestingOrder = "1";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
return resp;
|
return resp;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(
|
export async function handler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext,
|
ctx: FreshContext,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
ctx.state.flag = true;
|
ctx.state.flag = true;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HandlerContext, RouteConfig } from "$fresh/server.ts";
|
import { FreshContext, RouteConfig } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const handler = {
|
export const handler = {
|
||||||
GET(_req: Request, { params }: HandlerContext) {
|
GET(_req: Request, { params }: FreshContext) {
|
||||||
return new Response(params.path);
|
return new Response(params.path);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function BarLayout({ Component }: LayoutProps) {
|
export default function BarLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p class="baz-layout">Baz layout</p>
|
<p class="baz-layout">Baz layout</p>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function BarLayout({ Component }: LayoutProps) {
|
export default function BarLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p class="bar-layout">Bar layout</p>
|
<p class="bar-layout">Bar layout</p>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function FooLayout({ Component }: LayoutProps) {
|
export default function FooLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p class="foo-layout">Foo layout</p>
|
<p class="foo-layout">Foo layout</p>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
import { TestState } from "../_app.tsx";
|
import { TestState } from "../_app.tsx";
|
||||||
|
|
||||||
export async function handler(
|
export async function handler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<TestState>,
|
ctx: FreshContext<TestState>,
|
||||||
) {
|
) {
|
||||||
ctx.state.stateInProps = "look, i am set from middleware";
|
ctx.state.stateInProps = "look, i am set from middleware";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const handler = (_req: Request, ctx: MiddlewareHandlerContext) => {
|
export const handler = (_req: Request, ctx: FreshContext) => {
|
||||||
ctx.state = { handler1: "it works" };
|
ctx.state = { handler1: "it works" };
|
||||||
return ctx.next();
|
return ctx.next();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const handler = (_req: Request, ctx: MiddlewareHandlerContext) => {
|
export const handler = (_req: Request, ctx: FreshContext) => {
|
||||||
ctx.state.handler2 = "it works";
|
ctx.state.handler2 = "it works";
|
||||||
return ctx.next();
|
return ctx.next();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { HandlerContext, PageProps } from "$fresh/server.ts";
|
import { FreshContext, PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const handler = (_req: Request, ctx: HandlerContext) => {
|
export const handler = (_req: Request, ctx: FreshContext) => {
|
||||||
ctx.state.handler3 = "it works";
|
ctx.state.handler3 = "it works";
|
||||||
return ctx.render();
|
return ctx.render();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { HandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return <div>This is HTML</div>;
|
return <div>This is HTML</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handler = {
|
export const handler = {
|
||||||
GET(req: Request, { render }: HandlerContext) {
|
GET(req: Request, { render }: FreshContext) {
|
||||||
return render(undefined, {
|
return render(undefined, {
|
||||||
status: 401,
|
status: 401,
|
||||||
headers: { "x-some-header": "foo" },
|
headers: { "x-some-header": "foo" },
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { delay } from "$std/async/delay.ts";
|
import { delay } from "$std/async/delay.ts";
|
||||||
import { AppContext } from "$fresh/src/server/types.ts";
|
import { FreshContext } from "$fresh/src/server/types.ts";
|
||||||
|
|
||||||
export default async function App(req: Request, ctx: AppContext) {
|
export default async function App(req: Request, ctx: FreshContext) {
|
||||||
await delay(100);
|
await delay(100);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { LayoutContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
import { delay } from "$std/async/delay.ts";
|
import { delay } from "$std/async/delay.ts";
|
||||||
|
|
||||||
export default async function AsyncLayout(
|
export default async function AsyncLayout(
|
||||||
req: Request,
|
req: Request,
|
||||||
ctx: LayoutContext,
|
ctx: FreshContext,
|
||||||
) {
|
) {
|
||||||
await delay(10);
|
await delay(10);
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(
|
export async function handler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<{ data: string }>,
|
ctx: FreshContext<{ data: string }>,
|
||||||
) {
|
) {
|
||||||
ctx.state.data = "it works";
|
ctx.state.data = "it works";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { ErrorHandler, ErrorPageProps } from "../../../server.ts";
|
import { ErrorHandler, PageProps } from "../../../server.ts";
|
||||||
|
|
||||||
export const handler: ErrorHandler = (_req, ctx) => {
|
export const handler: ErrorHandler = (_req, ctx) => {
|
||||||
return ctx.render();
|
return ctx.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Error500Page({ error }: ErrorPageProps) {
|
export default function Error500Page({ error }: PageProps) {
|
||||||
return <p class="custom-500">Custom 500: {(error as Error).message}</p>;
|
return <p class="custom-500">Custom 500: {(error as Error).message}</p>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AppProps, Handler } from "$fresh/server.ts";
|
import { Handler, PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const handler: Handler = (_req, ctx) => {
|
export const handler: Handler = (_req, ctx) => {
|
||||||
ctx.state.lang = "de";
|
ctx.state.lang = "de";
|
||||||
@@ -6,7 +6,7 @@ export const handler: Handler = (_req, ctx) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function App(
|
export default function App(
|
||||||
{ Component, state }: AppProps<unknown, { lang: string }>,
|
{ Component, state }: PageProps<unknown, { lang: string }>,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<html lang={state.lang} class="html">
|
<html lang={state.lang} class="html">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function App({ Component, state }: AppProps) {
|
export default function App({ Component, state }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div class="app">
|
<div class="app">
|
||||||
<Component />
|
<Component />
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
import { LayoutState } from "./_middleware.ts";
|
import { LayoutState } from "./_middleware.ts";
|
||||||
|
|
||||||
export default function RootLayout(
|
export default function RootLayout(
|
||||||
{ Component, state }: LayoutProps<unknown, LayoutState>,
|
{ Component, state }: PageProps<unknown, LayoutState>,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<div class="root-layout">
|
<div class="root-layout">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export type LayoutState = {
|
export type LayoutState = {
|
||||||
something: string;
|
something: string;
|
||||||
@@ -6,7 +6,7 @@ export type LayoutState = {
|
|||||||
|
|
||||||
export const handler = (
|
export const handler = (
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<LayoutState>,
|
ctx: FreshContext<LayoutState>,
|
||||||
) => {
|
) => {
|
||||||
ctx.state.something = "it works";
|
ctx.state.something = "it works";
|
||||||
return ctx.next();
|
return ctx.next();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { LayoutContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
import { delay } from "$fresh/tests/deps.ts";
|
import { delay } from "$fresh/tests/deps.ts";
|
||||||
|
|
||||||
export default async function AsyncLayout(
|
export default async function AsyncLayout(
|
||||||
req: Request,
|
req: Request,
|
||||||
ctx: LayoutContext,
|
ctx: FreshContext,
|
||||||
) {
|
) {
|
||||||
await delay(10);
|
await delay(10);
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { LayoutContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
import { delay } from "$std/async/mod.ts";
|
import { delay } from "$std/async/mod.ts";
|
||||||
|
|
||||||
export default async function AsyncSubLayout(
|
export default async function AsyncSubLayout(
|
||||||
req: Request,
|
req: Request,
|
||||||
ctx: LayoutContext,
|
ctx: FreshContext,
|
||||||
) {
|
) {
|
||||||
await delay(10);
|
await delay(10);
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { LayoutContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default async function AsyncSubLayout(
|
export default async function AsyncSubLayout(
|
||||||
req: Request,
|
req: Request,
|
||||||
ctx: LayoutContext,
|
ctx: FreshContext,
|
||||||
) {
|
) {
|
||||||
await new Promise((r) => setTimeout(r, 10));
|
await new Promise((r) => setTimeout(r, 10));
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { h } from "preact";
|
import { h } from "preact";
|
||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function TsLayout({ Component }: LayoutProps) {
|
export default function TsLayout({ Component }: PageProps) {
|
||||||
return h("div", { class: "ts-layout" }, h(Component, null));
|
return h("div", { class: "ts-layout" }, h(Component, null));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { h } from "preact";
|
import { h } from "preact";
|
||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function TsxLayout({ Component }: LayoutProps) {
|
export default function TsxLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div class="tsx-layout">
|
<div class="tsx-layout">
|
||||||
<Component />
|
<Component />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function FooLayout({ Component }: LayoutProps) {
|
export default function FooLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div class="foo-layout">
|
<div class="foo-layout">
|
||||||
<Component />
|
<Component />
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { LayoutConfig, LayoutProps } from "$fresh/server.ts";
|
import { LayoutConfig, PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const config: LayoutConfig = {
|
export const config: LayoutConfig = {
|
||||||
skipInheritedLayouts: true,
|
skipInheritedLayouts: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function OverrideLayout({ Component }: LayoutProps) {
|
export default function OverrideLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div class="override-layout">
|
<div class="override-layout">
|
||||||
<Component />
|
<Component />
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { LayoutConfig, LayoutProps } from "$fresh/server.ts";
|
import { LayoutConfig, PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const config: LayoutConfig = {
|
export const config: LayoutConfig = {
|
||||||
skipAppWrapper: true,
|
skipAppWrapper: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function OverrideLayout({ Component }: LayoutProps) {
|
export default function OverrideLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div class="no-app-layout">
|
<div class="no-app-layout">
|
||||||
<Component />
|
<Component />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function SubLayout({ Component }: LayoutProps) {
|
export default function SubLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div class="sub-layout">
|
<div class="sub-layout">
|
||||||
<Component />
|
<Component />
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function RootLayout(
|
export default function RootLayout(
|
||||||
{ Component }: LayoutProps<unknown>,
|
{ Component }: PageProps<unknown>,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<div class="root-layout">
|
<div class="root-layout">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Layout({ Component }: LayoutProps) {
|
export default function Layout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div f-client-nav>
|
<div f-client-nav>
|
||||||
<Component />
|
<Component />
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
import { Partial } from "$fresh/runtime.ts";
|
import { Partial } from "$fresh/runtime.ts";
|
||||||
import { Fader } from "../../islands/Fader.tsx";
|
import { Fader } from "../../islands/Fader.tsx";
|
||||||
|
|
||||||
export default function AppLayout({ Component }: AppProps) {
|
export default function AppLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
import { Partial } from "$fresh/runtime.ts";
|
import { Partial } from "$fresh/runtime.ts";
|
||||||
import { Fader } from "../../islands/Fader.tsx";
|
import { Fader } from "../../islands/Fader.tsx";
|
||||||
|
|
||||||
export default function AppLayout({ Component }: AppProps) {
|
export default function AppLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
import { Partial } from "$fresh/runtime.ts";
|
import { Partial } from "$fresh/runtime.ts";
|
||||||
import { Fader } from "../../islands/Fader.tsx";
|
import { Fader } from "../../islands/Fader.tsx";
|
||||||
|
|
||||||
export default function AppLayout({ Component }: AppProps) {
|
export default function AppLayout({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export type IsPartialInContextState = {
|
export type IsPartialInContextState = {
|
||||||
setFromMiddleware: boolean;
|
setFromMiddleware: boolean;
|
||||||
@@ -7,7 +7,7 @@ export type IsPartialInContextState = {
|
|||||||
|
|
||||||
export async function handler(
|
export async function handler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<IsPartialInContextState>,
|
ctx: FreshContext<IsPartialInContextState>,
|
||||||
) {
|
) {
|
||||||
if (ctx.isPartial) {
|
if (ctx.isPartial) {
|
||||||
ctx.state.setFromMiddleware = true;
|
ctx.state.setFromMiddleware = true;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HandlerContext, Handlers, PageProps } from "../../../server.ts";
|
import { FreshContext, Handlers, PageProps } from "../../../server.ts";
|
||||||
|
|
||||||
export const handler: Handlers<unknown, { test: string }> = {
|
export const handler: Handlers<unknown, { test: string }> = {
|
||||||
async GET(_req, ctx: HandlerContext<unknown, { test: string }>) {
|
async GET(_req, ctx: FreshContext<{ test: string }, unknown>) {
|
||||||
const resp = await ctx.render();
|
const resp = await ctx.render();
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MiddlewareHandlerContext, Plugin } from "$fresh/server.ts";
|
import { FreshContext, Plugin } from "$fresh/server.ts";
|
||||||
import { handler as testMiddleware } from "./sample_routes/_middleware.ts";
|
import { handler as testMiddleware } from "./sample_routes/_middleware.ts";
|
||||||
import { AppBuilder } from "./sample_routes/AppBuilder.tsx";
|
import { AppBuilder } from "./sample_routes/AppBuilder.tsx";
|
||||||
import IslandPluginComponent from "./sample_routes/PluginRouteWithIsland.tsx";
|
import IslandPluginComponent from "./sample_routes/PluginRouteWithIsland.tsx";
|
||||||
@@ -16,14 +16,14 @@ export type PluginMiddlewareState = {
|
|||||||
const twoPointlessMiddlewares = [
|
const twoPointlessMiddlewares = [
|
||||||
async (
|
async (
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
ctx: FreshContext<PluginMiddlewareState>,
|
||||||
) => {
|
) => {
|
||||||
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
||||||
return await ctx.next();
|
return await ctx.next();
|
||||||
},
|
},
|
||||||
async (
|
async (
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
ctx: FreshContext<PluginMiddlewareState>,
|
||||||
) => {
|
) => {
|
||||||
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
||||||
return await ctx.next();
|
return await ctx.next();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
import { Head } from "../../../../runtime.ts";
|
import { Head } from "../../../../runtime.ts";
|
||||||
import { Options } from "../route-plugin.ts";
|
import { Options } from "../route-plugin.ts";
|
||||||
|
|
||||||
export function AppBuilder(options: Options) {
|
export function AppBuilder(options: Options) {
|
||||||
return ({ Component }: AppProps) => {
|
return ({ Component }: PageProps) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
import { PluginMiddlewareState } from "../../utils/route-plugin.ts";
|
import { PluginMiddlewareState } from "../../utils/route-plugin.ts";
|
||||||
|
|
||||||
export async function handler(
|
export async function handler(
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
ctx: FreshContext<PluginMiddlewareState>,
|
||||||
) {
|
) {
|
||||||
ctx.state.test = "look, i'm set from a plugin!";
|
ctx.state.test = "look, i'm set from a plugin!";
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MiddlewareHandlerContext, Plugin } from "$fresh/server.ts";
|
import { FreshContext, Plugin } from "$fresh/server.ts";
|
||||||
import { PluginMiddlewareState } from "./route-plugin.ts";
|
import { PluginMiddlewareState } from "./route-plugin.ts";
|
||||||
|
|
||||||
export default function secondMiddlewarePlugin(): Plugin<
|
export default function secondMiddlewarePlugin(): Plugin<
|
||||||
@@ -10,7 +10,7 @@ export default function secondMiddlewarePlugin(): Plugin<
|
|||||||
middleware: {
|
middleware: {
|
||||||
handler: async (
|
handler: async (
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
ctx: FreshContext<PluginMiddlewareState>,
|
||||||
) => {
|
) => {
|
||||||
return await ctx.next();
|
return await ctx.next();
|
||||||
},
|
},
|
||||||
@@ -20,7 +20,7 @@ export default function secondMiddlewarePlugin(): Plugin<
|
|||||||
middleware: {
|
middleware: {
|
||||||
handler: async (
|
handler: async (
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
ctx: FreshContext<PluginMiddlewareState>,
|
||||||
) => {
|
) => {
|
||||||
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
||||||
return await ctx.next();
|
return await ctx.next();
|
||||||
@@ -31,7 +31,7 @@ export default function secondMiddlewarePlugin(): Plugin<
|
|||||||
middleware: {
|
middleware: {
|
||||||
handler: async (
|
handler: async (
|
||||||
_req: Request,
|
_req: Request,
|
||||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
ctx: FreshContext<PluginMiddlewareState>,
|
||||||
) => {
|
) => {
|
||||||
return await ctx.next();
|
return await ctx.next();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
|
export async function handler(req: Request, ctx: FreshContext) {
|
||||||
console.log(ctx.destination);
|
console.log(ctx.destination);
|
||||||
console.log(req.url);
|
console.log(req.url);
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function App({ Component }: AppProps) {
|
export default function App({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function App({ Component }: AppProps) {
|
export default function App({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function App({ Component }: AppProps) {
|
export default function App({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function App({ Component }: AppProps) {
|
export default function App({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html className="bg-slate-800">
|
<html className="bg-slate-800">
|
||||||
<head className="bg-slate-800">
|
<head className="bg-slate-800">
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Partial } from "$fresh/runtime.ts";
|
import { Partial } from "$fresh/runtime.ts";
|
||||||
import { LayoutProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Layout(
|
export default function Layout(
|
||||||
{ Component }: LayoutProps<unknown, unknown>,
|
{ Component }: PageProps<unknown, unknown>,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<div f-client-nav>
|
<div f-client-nav>
|
||||||
|
|||||||
@@ -278,9 +278,9 @@ await start(manifest, { plugins: [twindPlugin(twindConfig)] });\n`;
|
|||||||
// Add default _app.tsx if not present
|
// Add default _app.tsx if not present
|
||||||
const routes = Array.from(Deno.readDirSync(join(srcDirectory, "routes")));
|
const routes = Array.from(Deno.readDirSync(join(srcDirectory, "routes")));
|
||||||
if (!routes.find((entry) => entry.isFile && entry.name.startsWith("_app."))) {
|
if (!routes.find((entry) => entry.isFile && entry.name.startsWith("_app."))) {
|
||||||
const APP_TSX = `import { AppProps } from "$fresh/server.ts";
|
const APP_TSX = `import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function App({ Component }: AppProps) {
|
export default function App({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import { AppProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function App({ Component }: AppProps) {
|
export default function App({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
Reference in New Issue
Block a user