A thin framework for running MoonBit components as Astro islands
Dependencies
[!NOTE] The MoonBit toolchain (moon CLI) is required, but astrobit build will install it automatically if not found.
npm install astrobit
// or
yarn add astrobitimport { defineConfig } from 'astro/config'
import astrobit from 'astrobit' // here
export default defineConfig({
integrations: [
astrobit() // and here
],
}){
"name": "yourname/your-project",
"deps": {
"SouichiroTsujimoto/astrobit": "0.1.6",
"mizchi/signals": "0.6.4"
},
"preferred-target": "js"
}moon installimport {
"SouichiroTsujimoto/astrobit" @a,
"SouichiroTsujimoto/astrobit/dom",
"mizchi/signals",
}
options(
link: { "js": { "exports": [ "mount", "render", "hydrate" ], "format": "esm" } },
)fn counter(props : @dom.Props) -> @a.Node {
let initial = props.get_int("initial")
let count = @signals.signal(initial)
@a.div([
@a.p(@a.dyn_text(fn() { "Count: " + count.get().to_string() })),
@a.button("-") |> @a.on_click(fn(_) { count.update(fn(n) { n - 1 }) }),
@a.button("+") |> @a.on_click(fn(_) { count.update(fn(n) { n + 1 }) }),
])
}
pub fn mount(element : @dom.Element, props : @dom.Props) -> Unit {
@a.mount_dom(element, counter(props))
}
pub fn render(props : @dom.Props) -> String {
@a.render_to_html(counter(props))
}
pub fn hydrate(element : @dom.Element, props : @dom.Props) -> Unit {
@a.hydrate_dom(element, counter(props))
}props.get_int("key") // Int (default: 0)
props.get_string("key") // String (default: "")
props.get_bool("key") // Bool (default: false)
props.get_int("key", default=10) // with explicit default---
import Counter from '../components/counter/counter.mbt'
---
<!-- client:only — mount on the client, no SSR -->
<Counter client:only="astrobit" initial={0} />
<!-- client:load — SSR + hydration -->
<Counter client:load initial={0} />{
"scripts": {
"build": "astrobit build"
}
}moon buildnpm run devInstall
Download zipA thin framework for running MoonBit components as Astro islands
Dependencies