Skip to main content

tutorial_tasks/
lib.rs

1//! A task list built with ravenrs-app.
2use ravenrs_app::BusinessObject;
3use ravenrs_app_ui::{App, Language};
4
5#[derive(BusinessObject)]
6#[object(caption = "Tarefas", navigation = "Organização", icon = "list")]
7struct Task {
8    #[field(key)]
9    id: i64,
10    #[field(caption = "Título", default_property, required)]
11    title: String,
12    #[field(caption = "Concluída")]
13    done: bool,
14}
15
16/// Navigation, lists and forms backed by an in-memory object space.
17pub fn app() -> ravenrs::prelude::AnyView {
18    tasks().into_view()
19}
20
21/// The application before it is mounted.
22pub fn tasks() -> App {
23    App::new("Minhas tarefas").language(Language::BrazilianPortuguese).entity::<Task>()
24}
25
26#[cfg(target_arch = "wasm32")]
27mod web_entry {
28    use std::cell::RefCell;
29
30    use wasm_bindgen::prelude::*;
31
32    thread_local! {
33        static APP: RefCell<Option<ravenrs::web::WebApp>> = const { RefCell::new(None) };
34    }
35
36    /// Runs automatically when the module is instantiated.
37    #[wasm_bindgen(start)]
38    pub fn start() {
39        console_error_panic_hook::set_once();
40        wasm_bindgen_futures::spawn_local(async {
41            match ravenrs::web::start(super::app(), ravenrs::web::WebOptions::new("raven-canvas")).await {
42                Ok(app) => APP.with(|a| *a.borrow_mut() = Some(app)),
43                Err(e) => web_sys::console::error_1(&e.to_string().into()),
44            }
45        });
46    }
47
48    /// Unmounts the app and releases its listeners and GPU resources.
49    #[wasm_bindgen]
50    pub fn stop() {
51        APP.with(|a| a.borrow_mut().take());
52    }
53}