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

36 lines
956 B
Scheme

(define-macro (mithril:init)
"(mithril:init)
Loads Mithril into the document head and sets the
pragma->sxml function."
`(begin (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 (and (not (null? args))
(= (remainder (length args) 2 1)))
(error (format
"mithril:comp-> Component macro expects even length args list.
Call: (mithril:comp ~s ~s)"
view args)))
`(object
:view
(lambda (vnode) (,@view))
,@args))