# How it compiles

> Status: implemented are markup as HTML, components of the server, their results, `Response`
> going up, `Content<T>`, component values with a result, decorators with guards, wrappers that
> take the body and the request context, routes, and `rooklang/server`; the server of the site, `site/server/main.rk`, is written
> with them, and the guide has a section on them. The decisions are collected at the end of the
> document, together with what is not decided yet. Server markup, components and `rooklang/server`
> remain **experimental** in 1.x and may change between releases.

> This document builds on [components.md](https://github.com/QWERN-9876r/RookLang/blob/HEAD/docs/components.md): components, decorators, context,
> components as values. It describes only what is different on the server.

Every component of the server is a function of its properties and the context; markup is a template
string. The names inside are internal, as for the browser.

```go
comp Header() {
    return <header>{@session.user?.name ?? "Guest"}</header>
}

comp Page(title string) {
    return <main><Header /><h1>{title}</h1><Feed /></main>
}
```

```js
async function $$Header($$props, $$ctx) {
  const { user: $$session$user } = $$need($$ctx, 'session', 'Header')
  return $$html`<header>${$$session$user?.name ?? 'Guest'}</header>`
}

async function $$Page({ title }, $$ctx) {
  return await $$html`<main>${$$Header({}, $$ctx)}<h1>${title}</h1>${$$Feed({}, $$ctx)}</main>`
}
```

- **`$$html`** is a tag of the template: it escapes strings and numbers, puts `Html` in as it is,
  joins arrays, leaves out `null`, and throws an internal value with a `Response` when one is a
  child. The calls of the components among its values have all started when the template is
  evaluated, so they run side by side: the tag waits for all of them, also when one fails or gives
  a `Response`, so that the `defer` of each runs before the request ends.
- **`{for}`, `{if}` and `{switch}`** run once, in a function whose blocks push their markup into
  an array, which the template gets as a value.
- **A decorator** is inlined into the function of the component, as in the browser; a guard is a
  `return` of that function. After the bodies of its decorators, the component puts their public
  members into the context of the components it uses:
  `$$ctx = $$provide($$ctx, { session: { url: $$session$url, user: $$session$user } })`.
- **`handler`** calls the root with the properties of the request, catches the `Response` that went
  up and turns the result into a response by the table above.
- **Inlining.** A component of the server is not inlined: there are no updates to save, and a
  function per component keeps the output close to the source. A small component may be inlined
  later, if a benchmark shows that it pays.

