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.
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { FreshContext, Plugin } from "$fresh/server.ts";
|
|
import { PluginMiddlewareState } from "./route-plugin.ts";
|
|
|
|
export default function secondMiddlewarePlugin(): Plugin<
|
|
PluginMiddlewareState
|
|
> {
|
|
return {
|
|
name: "secondMiddlewarePlugin",
|
|
middlewares: [{
|
|
middleware: {
|
|
handler: async (
|
|
_req: Request,
|
|
ctx: FreshContext<PluginMiddlewareState>,
|
|
) => {
|
|
return await ctx.next();
|
|
},
|
|
},
|
|
path: "/", // this is the root route
|
|
}, {
|
|
middleware: {
|
|
handler: async (
|
|
_req: Request,
|
|
ctx: FreshContext<PluginMiddlewareState>,
|
|
) => {
|
|
ctx.state.num = ctx.state.num === undefined ? 1 : ctx.state.num + 1;
|
|
return await ctx.next();
|
|
},
|
|
},
|
|
path: "lots-of-middleware/",
|
|
}, {
|
|
middleware: {
|
|
handler: async (
|
|
_req: Request,
|
|
ctx: FreshContext<PluginMiddlewareState>,
|
|
) => {
|
|
return await ctx.next();
|
|
},
|
|
},
|
|
path: "", // this also goes to the root route, as of 1.4
|
|
}],
|
|
};
|
|
}
|