uce/site/doc/pages/1_COMPONENT.txt

37 lines
1.2 KiB
Plaintext

:sig
COMPONENT(Request& context)
:desc
Defines the default component entrypoint for the current `.uce` file.
`component()` and `component_render()` invoke `COMPONENT(Request& context)` by default. Named component entrypoints use `COMPONENT:NAME(Request& context)`.
This keeps page rendering and component rendering separate:
- direct HTTP requests call `RENDER(Request& context)`
- WebSocket messages call `WS(Request& context)`
- component helpers call `COMPONENT(Request& context)` or `COMPONENT:NAME(Request& context)`
A file intended only for component reuse can define `COMPONENT()` without defining `RENDER()`.
Inside component handlers, props arrive through `context.call`.
When you call `component(":NAME", props, context)` or `component_render(":NAME", props, context)`, the runtime resolves `:NAME` against the current `.uce` file instead of requiring the file name again.
Examples:
`COMPONENT(Request& context)`
`{`
` <><section><?: component(":BODY", context.call, context) ?></section></>`
`}`
`COMPONENT:BODY(Request& context)`
`{`
` <><p><?= context.call["body"] ?></p></>`
`}`
:see
>component
>component_render
>1_RENDER
>1_WS