21 releases

0.5.0 Apr 5, 2024
0.4.3 Feb 28, 2024
0.4.1 Dec 2, 2023
0.4.0 Nov 8, 2023
0.1.0-alpha.0 Dec 23, 2020

#159 in Web programming

Download history 2/week @ 2024-02-02 4/week @ 2024-02-16 118/week @ 2024-02-23 44/week @ 2024-03-01 9/week @ 2024-03-08 5/week @ 2024-03-15 18/week @ 2024-03-29 129/week @ 2024-04-05

152 downloads per month
Used in 5 crates

MIT/Apache

475KB
13K SLoC

Rust 9K SLoC // 0.0% comments TypeScript 2K SLoC // 0.0% comments JavaScript 2K SLoC // 0.0% comments

Vertigo

A reactive Real-DOM library with SSR for Rust

crates.io Documentation MIT or Apache 2.0 licensed Dependency Status CI downloads

Features

  • Reactive dependencies - A graph of values and clients (micro-subscriptions) that can automatically compute what to refresh after one value change
  • Real DOM - No intermediate Virtual DOM mechanism is necessary
  • HTML/CSS macros - Allows to construct Real DOM nodes using HTML and CSS
  • Server-side rendering - Out of the box when using vertigo-cli

See Changelog for recent features.

Go to TUTORIAL if you want to try.

Examples

Dependencies:

vertigo = "0.5"

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.

Installation of vertigo-cli tool

To ease process or development use vertigo-cli tool that allows to build, serve and watch your project.

cargo install --force vertigo-cli

Demo App

Prepare

Make sure you're using nightly version of rust:

  • rustup default nightly

Install cargo-make and vertigo-cli:

  • cargo install cargo-make vertigo-cli

Run

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

A community, soon to grow

Dependencies

~4.5MB
~93K SLoC