Skip to content

Commit

Permalink
[docs] sync updates from #1778 and #1791 (#1802)
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb authored Jul 2, 2021
1 parent 8bc7c77 commit 8828743
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
15 changes: 10 additions & 5 deletions documentation/docs/01-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Endpoints are modules written in `.js` (or `.ts`) files that export functions co

```ts
type Headers = Record<string, string>;
type DefaultBody = JSONValue | Uint8Array;

type Request<Locals = Record<string, any>, Body = unknown> = {
method: string;
Expand All @@ -62,15 +63,19 @@ type Request<Locals = Record<string, any>, Body = unknown> = {
locals: Locals; // populated by hooks handle
};

type EndpointOutput = {
type EndpointOutput<Body extends DefaultBody = DefaultBody> = {
status?: number;
headers?: Headers;
body?: string | Uint8Array | JSONValue;
body?: Body;
};

type RequestHandler<Locals = Record<string, any>> = (
request: Request<Locals>
) => void | EndpointOutput | Promise<EndpointOutput>;
type RequestHandler<
Locals = Record<string, any>,
Input = unknown,
Output extends DefaultBody = DefaultBody
> = (
request: Request<Locals, Input>
) => void | EndpointOutput<Output> | Promise<void | EndpointOutput<Output>>;
```

```js
Expand Down
22 changes: 15 additions & 7 deletions documentation/docs/03-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ A component that defines a page or a layout can export a `load` function that ru
Our example blog page might contain a `load` function like the following. Note the `context="module"` — this is necessary because `load` runs before the component is rendered:

```ts
type LoadInput = {
type LoadInput<
PageParams extends Record<string, string> = Record<string, string>,
Context extends Record<string, any> = Record<string, any>,
Session = any
> = {
page: {
host: string;
path: string;
params: Record<string, string>;
params: PageParams;
query: URLSearchParams;
};
fetch: (info: RequestInfo, init?: RequestInit) => Promise<Response>;
session: any;
context: Record<string, any>;
session: Session;
context: Context;
};

type LoadOutput = {
type LoadOutput<
Props extends Record<string, any> = Record<string, any>,
Context extends Record<string, any> = Record<string, any>
> = {
status?: number;
error?: string | Error;
redirect?: string;
props?: Record<string, any>;
context?: Record<string, any>;
props?: Props;
context?: Context;
maxage?: number;
};

```

```html
Expand Down

0 comments on commit 8828743

Please sign in to comment.