sauron
0.40.0
Sauron 은 인체 공학, 단순성 및 우아함에 중점을 둔 클라이언트 측 및/또는 서버 측 웹 애플리케이션을 구축하기위한 다양한 웹 프레임 워크 및 라이브러리입니다. 이를 통해 가능한 최소량의 코드를 작성하고 프레임 워크의 내부 세부 사항보다는 비즈니스 로직에 더 집중할 수 있습니다.
Sauron은 Elm-Lang에서 영감을 얻었으며 Elm 아키텍처를 따르고 있습니다.
Sauron 응용 프로그램에는 모델,보기 및 업데이트 만 있습니다. 모델은 응용 프로그램 상태입니다. 보기는 모델을 사용자에게 제시하는 방법을 설명합니다. 업데이트 기능은 모델을 업데이트하는 방법을 설명합니다.이 메시지는 모델 업데이트에 필요한 데이터가 포함 된 메시지를 사용합니다.
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 로 가십시오.
구축 및 서빙 명령에 대한 자세한 내용은이 repo의 예제를 살펴보십시오. 각 스크립트에는 빌드 및 실행 방법에 대한 스크립트가 있습니다.
라이센스 : MIT