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:
@@ -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 { AppBuilder } from "./sample_routes/AppBuilder.tsx";
|
||||
import IslandPluginComponent from "./sample_routes/PluginRouteWithIsland.tsx";
|
||||
@@ -16,14 +16,14 @@ export type PluginMiddlewareState = {
|
||||
const twoPointlessMiddlewares = [
|
||||
async (
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
||||
ctx: FreshContext<PluginMiddlewareState>,
|
||||
) => {
|
||||
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
||||
return await ctx.next();
|
||||
},
|
||||
async (
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
||||
ctx: FreshContext<PluginMiddlewareState>,
|
||||
) => {
|
||||
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
||||
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 { Options } from "../route-plugin.ts";
|
||||
|
||||
export function AppBuilder(options: Options) {
|
||||
return ({ Component }: AppProps) => {
|
||||
return ({ Component }: PageProps) => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { PluginMiddlewareState } from "../../utils/route-plugin.ts";
|
||||
|
||||
export async function handler(
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
||||
ctx: FreshContext<PluginMiddlewareState>,
|
||||
) {
|
||||
ctx.state.test = "look, i'm set from a plugin!";
|
||||
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";
|
||||
|
||||
export default function secondMiddlewarePlugin(): Plugin<
|
||||
@@ -10,7 +10,7 @@ export default function secondMiddlewarePlugin(): Plugin<
|
||||
middleware: {
|
||||
handler: async (
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
||||
ctx: FreshContext<PluginMiddlewareState>,
|
||||
) => {
|
||||
return await ctx.next();
|
||||
},
|
||||
@@ -20,7 +20,7 @@ export default function secondMiddlewarePlugin(): Plugin<
|
||||
middleware: {
|
||||
handler: async (
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
||||
ctx: FreshContext<PluginMiddlewareState>,
|
||||
) => {
|
||||
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
||||
return await ctx.next();
|
||||
@@ -31,7 +31,7 @@ export default function secondMiddlewarePlugin(): Plugin<
|
||||
middleware: {
|
||||
handler: async (
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<PluginMiddlewareState>,
|
||||
ctx: FreshContext<PluginMiddlewareState>,
|
||||
) => {
|
||||
return await ctx.next();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user