mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00

Implements the new `module` header syntax as described in "module and package changes" [1]: ``` module [Request, Response, req] ``` The old syntax should still work fine, and is automatically upgraded to the new one when running `roc format`. [1] https://docs.google.com/document/d/1E_77fO-44BtoBtXoVeWyGh1xN2KRTWTu8q6i25RNNx0/edit
36 lines
761 B
Text
36 lines
761 B
Text
module [exampleApp, State]
|
|
|
|
import pf.Html exposing [App, Html, html, head, body, div, text, h1]
|
|
|
|
State : {
|
|
answer : U32,
|
|
}
|
|
|
|
exampleApp : App State State
|
|
exampleApp = {
|
|
init,
|
|
render,
|
|
wasmUrl: "assets/example-client.wasm",
|
|
}
|
|
|
|
init = \result ->
|
|
when result is
|
|
Ok state -> state
|
|
Err _ -> { answer: 0 }
|
|
|
|
render : State -> Html State
|
|
render = \state ->
|
|
num = Num.toStr state.answer
|
|
|
|
html [] [
|
|
head [] [],
|
|
body [] [
|
|
h1 [] [text "The app"],
|
|
div [] [text "The answer is $(num)"],
|
|
],
|
|
]
|
|
|
|
expect
|
|
Html.renderStatic (Html.translateStatic (render { answer: 42 }))
|
|
==
|
|
"<!DOCTYPE html><html><head></head><body><h1>The app</h1><div>The answer is 42</div></body></html>"
|