nitinol/mithril.scm
2026-07-12 12:00:54 +08:00

31 lines
837 B
Scheme

(define (mithril:init)
"(mithril:init)
Loads Mithril into the document head and sets the
pragma->sxml function."
(get-resource "https://cdnjs.cloudflare.com/ajax/libs/mithril/2.2.2/mithril.min.js")
(pragma->sxml m))
(define-macro (mithril:comp view . args)
"(mithril:comp view . args)
Creates a Mithril component object, where VIEW is
a function body used to display the component, and
ARGS is a list of keyword-value pairs that specify
additional values on the component object.
For example, the following code creates a stateful
heading component:
```
(define Heading
(component
(sxml
(h1 ~vnode.state.title))
:title \"Title Text\"))
```"
(when (= (remainder (length args) 2 1))
(error "Component macro expects even length args list."))
`(object
:view
(lambda (vnode) (,@view))
,@args))