nusa

Crates.ionusa
lib.rsnusa
version0.1.9
sourcesrc
created_at2022-04-01 09:20:00.42943
updated_at2023-01-27 07:29:15.489705
descriptionweb-frontend features for kagura
homepage
repositoryhttps://github.com/SoundRabbit/Kagura
max_upload_size
id560183
size86,421
(SoundRabbit)

documentation

README

nusa

The features for kagura to generate web page by virtual-DOM.

Documents

https://kagura.gitbook.io/kagura-nusa-en/

Usage

mount to real-DOM

You can begin application with kagura::Runtime::run. nusa::dom_node::BasicDomNode is features to mount virtual-DOM to real-DOM.

extern crate js_sys;
extern crate kagura;
extern crate nusa;
extern crate wasm_bindgen;
extern crate wasm_bindgen_futures;
extern crate web_sys;

use nusa::prelude::*;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn main() {
    wasm_bindgen_futures::spawn_local(async {
        kagura::Runtime::run(nusa::dom_node::BasicDomNode::new(entry_point(), |_| {
            vec![Html::h1(
                Attributes::new(),
                Events::new(),
                vec![Html::text("Hello World")],
            )]
        }))
        .await;
    });
}

fn entry_point() -> web_sys::Node {
    web_sys::window()
        .unwrap()
        .document()
        .unwrap()
        .get_element_by_id("app")
        .unwrap()
        .into()
}

with internal SVG

extern crate js_sys;
extern crate kagura;
extern crate nusa;
extern crate wasm_bindgen;
extern crate wasm_bindgen_futures;
extern crate web_sys;

use nusa::prelude::*;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn main() {
    wasm_bindgen_futures::spawn_local(async {
        kagura::Runtime::run(nusa::dom_node::BasicDomNode::new(entry_point(), |_| {
            vec![Html::element(
                "svg",
                Attributes::new()
                    .string("width", "400")
                    .string("height", "200")
                    .string("viewBox", "0 0 400 200")
                    .string("xmlns", "http://www.w3.org/2000/svg"),
                Events::new(),
                vec![Html::element(
                    "rect",
                    Attributes::new()
                        .num("x", 10.0)
                        .num("y", 10.0)
                        .num("width", 380.0)
                        .num("height", 180.0)
                        .string("fill", "#e74c3c"),
                    Events::new(),
                    vec![],
                )],
            )]
        }))
        .await;
    });
}

fn entry_point() -> web_sys::Node {
    web_sys::window()
        .unwrap()
        .document()
        .unwrap()
        .get_element_by_id("app")
        .unwrap()
        .into()
}
Commit count: 545

cargo fmt