sauron
0.40.0
サウロンは、人間工学、シンプル、エレガンスに重点を置いたクライアント側および/またはサーバー側のWebアプリケーションを構築するための多目的なWebフレームワークおよびライブラリです。これにより、可能な限り少ない量のコードを記述し、フレームワークの内的な詳細ではなく、ビジネスロジックにもっと焦点を合わせることができます。
サウロンはエルム・ラングに触発され、エルムの建築に従っています。
サウロンアプリケーションには、モデル、ビュー、更新のみがあります。モデルはアプリケーションの状態です。ビューでは、モデルをユーザーに提示する方法について説明しています。更新関数は、モデルの更新方法を説明します。これは、モデルの更新に必要なデータを含むメッセージを使用します。
src/lib.rsで
use sauron :: {
html :: text , html :: units :: px , jss , node , wasm_bindgen , Application , Cmd , Node , Program ,
} ;
enum Msg {
Increment ,
Decrement ,
Reset ,
}
struct App {
count : i32 ,
}
impl App {
fn new ( ) -> Self {
App { count : 0 }
}
}
impl Application for App {
type MSG = Msg ;
fn view ( & self ) -> Node < Msg > {
node ! {
<main>
<input type = "button"
value= "+"
on_click=|_| {
Msg :: Increment
}
/>
<button class= "count" on_click=|_| { Msg :: Reset } > { text ( self . count ) } </button>
<input type = "button"
value= "-"
on_click=|_| {
Msg :: Decrement
}
/>
</main>
}
}
fn update ( & mut self , msg : Msg ) -> Cmd < Msg > {
match msg {
Msg :: Increment => self . count += 1 ,
Msg :: Decrement => self . count -= 1 ,
Msg :: Reset => self . count = 0 ,
}
Cmd :: none ( )
}
fn stylesheet ( ) -> Vec < String > {
vec ! [ jss! {
"body" : {
font_family : "verdana, arial, monospace" ,
} ,
"main" : {
width : px ( 30 ) ,
height : px ( 100 ) ,
margin : "auto" ,
text_align : "center" ,
} ,
"input, .count" : {
font_size : px ( 40 ) ,
padding : px ( 30 ) ,
margin : px ( 30 ) ,
}
} ]
}
}
# [ wasm_bindgen ( start ) ]
pub fn start ( ) {
Program :: mount_to_body ( App :: new ( ) ) ;
} index.html
<!doctype html >
< html >
< head >
< meta content =" text/html;charset=utf-8 " http-equiv =" Content-Type " />
< title > Counter </ title >
< script type = module >
import init from './pkg/counter.js' ;
await init ( ) . catch ( console . error ) ;
</ script >
</ head >
< body >
</ body >
</ html > Cargo.tomlで、クレート型をcdylibに指定します
[ package ]
name = " counter "
version = " 0.1.0 "
edition = " 2021 "
[ lib ]
crate-type = [ " cdylib " ]
[ dependencies ]
sauron = " 0.61.0 " cargo install wasm-pack
cargo install basic-http-server使用してビルドします
wasm-pack build --target web --release使用してサーブします
basic-http-server -a 0.0.0.0:4000次に、http:// localhost:4000に移動します
完全なチュートリアルについては、 getting-started.mdにアクセスしてください。
構築と提供するコマンドの詳細については、このリポジトリの例をご覧ください。それぞれに、それらを構築して実行する方法に関するスクリプトがあります。
ライセンス:MIT