Crates.io | vertigo |
lib.rs | vertigo |
version | 0.6.0 |
source | src |
created_at | 2020-12-23 12:47:14.624989 |
updated_at | 2024-08-02 20:18:10.154679 |
description | Reactive Real-DOM library with SSR for Rust |
homepage | https://github.com/vertigo-web/ |
repository | https://github.com/vertigo-web/vertigo |
max_upload_size | |
id | 326495 |
size | 570,371 |
A reactive Real-DOM library with SSR for Rust
vertigo-cli
See Changelog for recent features.
Go to TUTORIAL if you want to try.
Dependencies:
vertigo = "0.6"
Example 1:
use vertigo::{dom, DomNode, Value, bind, main};
#[main]
pub fn app() -> DomNode {
let count = Value::new(0);
let increment = bind!(count, || {
count.change(|value| {
*value += 1;
});
});
let decrement = bind!(count, || {
count.change(|value| {
*value -= 1;
});
});
dom! {
<html>
<head/>
<body>
<div>
<p>"Counter: " { count }</p>
<button on_click={decrement}>"-"</button>
<button on_click={increment}>"+"</button>
</div>
</body>
</html>
}
}
Example 2:
use vertigo::{css, component, DomNode, Value, dom, main};
#[component]
pub fn MyMessage(message: Value<String>) {
dom! {
<p>
"Message to the world: "
{ message }
</p>
}
}
#[main]
fn app() -> DomNode {
let message = Value::new("Hello world!".to_string());
let main_div = css!("
color: darkblue;
");
dom! {
<html>
<head/>
<body>
<div css={main_div}>
<MyMessage message={message} />
</div>
</body>
</html>
}
}
Take a look at More examples here.
vertigo-cli
toolTo ease process or development use vertigo-cli tool that allows to build, serve and watch your project.
cargo install --force vertigo-cli
Make sure you're using nightly version of rust:
rustup default nightly
Install cargo-make and vertigo-cli:
cargo install cargo-make vertigo-cli
Build and run project using:
cargo make demo-start
Eventually terminal will let you know that app is available under http://localhost:4444/
If you want to play around with the code, you can make cargo to watch for your changes:
cargo make demo-watch
The browser will automatically refresh after the project has been recompiled.
If you want to use "chat" in demo you need to first run websocket server in separate terminal with command:
cargo make demo-serve-api
To run the examples in watch mode (they will run on localhost:4444):
cargo make examples-counter
or cargo make examples-router
or cargo make examples-trafficlights