Introduction
Sauron is a web framework written in rust, which can compile to webassembly to help you create robust websites and web apps.
This guide will:
- Show you how to make interactive apps with Sauron web framework.
A Quick Example
1use sauron::html::text;2use sauron::prelude::*;3use sauron::{node, Cmd, Component, Node, Program};45#[derive(Debug)]6pub enum Msg {7 Increment,8 Decrement,9}1011pub struct App {12 count: i32,13}1415impl App {16 pub fn new() -> Self {17 App { count: 0 }18 }19}2021impl Component<Msg> for App {22 fn view(&self) -> Node<Msg> {23 node! {24 <main>25 <input type="button"26 value="+"27 key=128 on_click={|_| {29 Msg::Increment30 }}31 />32 <div>{text(self.count)}</div>33 <input type="button"34 value="-"35 key=136 on_click={|_| {37 Msg::Decrement38 }}39 />40 </main>41 }42 }4344 fn update(&mut self, msg: Msg) -> Cmd<Self, Msg> {45 match msg {46 Msg::Increment => self.count += 1,47 Msg::Decrement => self.count -= 1,48 }49 Cmd::none()50 }51}5253#[wasm_bindgen(start)]54pub fn main() {55 console_log::init_with_level(log::Level::Trace).unwrap();56 console_error_panic_hook::set_once();57 Program::mount_to_body(App::new());58}
Why sauron?
- No runtime errors in practice
- Reliable refactoring
- Automatically enforced semantic versioning for all dependent crates.