WIP: move to static props
This commit is contained in:
1 parent
c5089ba3c5
commit
c1fd848f89
37 files changed
+1014
-339
No files matched your search
@@ -1,27 +1,34 @@
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, rc::Rc};
|
||||
|
||||
use dioxus_core::prelude::*;
|
||||
use recoil::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
const TODOS: AtomFamily<Uuid, Todo> = |_| HashMap::new();
|
||||
const TODOS: AtomHashMap<Uuid, Rc<Todo>> = |map| {};
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct Todo {
|
||||
checked: bool,
|
||||
title: String,
|
||||
contents: String,
|
||||
content: String,
|
||||
}
|
||||
|
||||
static App: FC<()> = |ctx, _| {
|
||||
use_init_recoil_root(ctx, |_| {});
|
||||
use_init_recoil_root(ctx, move |cfg| {});
|
||||
|
||||
let todos = use_read_family(ctx, &TODOS);
|
||||
|
||||
rsx! { in ctx,
|
||||
div {
|
||||
"Basic Todolist with AtomFamilies in Recoil.rs"
|
||||
}
|
||||
}
|
||||
// rsx! { in ctx,
|
||||
// div {
|
||||
// h1 {"Basic Todolist with AtomFamilies in Recoil.rs"}
|
||||
// ul { { todos.keys().map(|id| rsx! { Child { id: *id } }) } }
|
||||
// }
|
||||
// }
|
||||
ctx.render(html! {
|
||||
<a href="#" class="">
|
||||
<img class="inline-block h-10 w-10 rounded-full object-cover ring-2 ring-white" src="/images/person/4.jpg" alt="Jade"/>
|
||||
</a>
|
||||
})
|
||||
};
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
@@ -33,11 +40,11 @@ static Child: FC<ChildProps> = |ctx, props| {
|
||||
let (todo, set_todo) = use_read_write(ctx, &TODOS.select(&props.id));
|
||||
|
||||
rsx! { in ctx,
|
||||
div {
|
||||
li {
|
||||
h1 {"{todo.title}"}
|
||||
input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
|
||||
label { "{todo.contents}", for: "scales" }
|
||||
p {"{todo.contents}"}
|
||||
label { "{todo.content}", for: "scales" }
|
||||
p {"{todo.content}"}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
use dioxus_core::prelude::*;
|
||||
use im_rc::HashMap as ImMap;
|
||||
use recoil::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
const TODOS: Atom<ImMap<Uuid, Todo>> = |_| ImMap::new();
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct Todo {
|
||||
checked: bool,
|
||||
title: String,
|
||||
contents: String,
|
||||
}
|
||||
|
||||
static App: FC<()> = |ctx, _| {
|
||||
use_init_recoil_root(ctx, |_| {});
|
||||
let todos = use_read(ctx, &TODOS);
|
||||
|
||||
rsx! { in ctx,
|
||||
div {
|
||||
"Basic Todolist with AtomFamilies in Recoil.rs"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
struct ChildProps {
|
||||
id: Uuid,
|
||||
}
|
||||
|
||||
static Child: FC<ChildProps> = |ctx, props| {
|
||||
let todo = use_read(ctx, &TODOS).get(&props.id).unwrap();
|
||||
// let (todo, set_todo) = use_read_write(ctx, &TODOS);
|
||||
|
||||
rsx! { in ctx,
|
||||
div {
|
||||
h1 {"{todo.title}"}
|
||||
input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
|
||||
label { "{todo.contents}", for: "scales" }
|
||||
p {"{todo.contents}"}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn main() {
|
||||
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
|
||||
}
|
||||
@@ -11,12 +11,19 @@ static App: FC<()> = |ctx, _| {
|
||||
rsx! { in ctx,
|
||||
div {
|
||||
"Count: {count}"
|
||||
button { onclick: move |_| set_count(count + 1), "Incr" }
|
||||
button { onclick: move |_| set_count(count - 1), "Decr" }
|
||||
br {}
|
||||
button { onclick: move |_| set_count(count + 1), "<Incr" }
|
||||
">___<"
|
||||
button { onclick: move |_| set_count(count - 1), "Decr>" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn main() {
|
||||
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
|
||||
// Setup logging
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
log::debug!("asd");
|
||||
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App));
|
||||
}
|
||||
@@ -3,8 +3,8 @@ use std::collections::HashMap;
|
||||
use dioxus_core::prelude::*;
|
||||
use recoil::*;
|
||||
|
||||
const A_ITEMS: AtomFamily<i32, i32> = |_| HashMap::new();
|
||||
const B_ITEMS: AtomFamily<i32, i32> = |_| HashMap::new();
|
||||
const A_ITEMS: AtomHashMap<i32, i32> = |_| HashMap::new();
|
||||
const B_ITEMS: AtomHashMap<i32, i32> = |_| HashMap::new();
|
||||
|
||||
const C_SELECTOR: SelectorFamily<i32, i32> = |api, key| {
|
||||
let a = api.get(&A_ITEMS.select(&key));
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
println!("asd")
|
||||
Reference in new issue
Block a user