feat: amazingly awesome error handling
This commit is contained in:
1 parent
05c909f320
commit
4a72b3140b
58 files changed
+248
-1219
No files matched your search
@@ -45,7 +45,7 @@ struct IncrementerProps<'a> {
|
||||
onclick: &'a dyn Fn(MouseEvent),
|
||||
}
|
||||
|
||||
fn C1<'a, 'b>(cx: Context<'a, IncrementerProps<'b>>) -> VNode<'a> {
|
||||
fn C1<'a, 'b>(cx: Context<'a, IncrementerProps<'b>>) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
class: "inline-block py-4 px-8 mr-6 leading-none text-white bg-indigo-600 hover:bg-indigo-900 font-semibold rounded shadow"
|
||||
|
||||
@@ -160,7 +160,7 @@ struct CalculatorKeyProps<'a> {
|
||||
onclick: &'a dyn Fn(MouseEvent),
|
||||
}
|
||||
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> VNode<'a> {
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
class: "calculator-key {cx.name}"
|
||||
@@ -175,7 +175,7 @@ struct CalculatorDisplayProps<'a> {
|
||||
val: &'a str,
|
||||
}
|
||||
|
||||
fn CalculatorDisplay<'a>(cx: Context<'a, CalculatorDisplayProps>) -> VNode<'a> {
|
||||
fn CalculatorDisplay<'a>(cx: Context<'a, CalculatorDisplayProps>) -> DomTree<'a> {
|
||||
use separator::Separatable;
|
||||
// Todo, add float support to the num-format crate
|
||||
let formatted = cx.val.parse::<f64>().unwrap().separated_string();
|
||||
|
||||
@@ -52,7 +52,7 @@ struct ButtonProps {
|
||||
id: u8,
|
||||
}
|
||||
|
||||
fn CustomButton(cx: Context<ButtonProps>) -> VNode {
|
||||
fn CustomButton(cx: Context<ButtonProps>) -> DomTree {
|
||||
let names = cx.use_context::<CustomContext>();
|
||||
let name = names.0[cx.id as usize];
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(CustomA))
|
||||
}
|
||||
|
||||
fn CustomA(cx: Context<()>) -> VNode {
|
||||
fn CustomA(cx: Context<()>) -> DomTree {
|
||||
let (val, set_val) = use_state_classic(cx, || "abcdef".to_string() as String);
|
||||
|
||||
cx.render(rsx! {
|
||||
@@ -43,7 +43,7 @@ mod components {
|
||||
val: String,
|
||||
}
|
||||
|
||||
pub fn CustomB(cx: Context<PropsB>) -> VNode {
|
||||
pub fn CustomB(cx: Context<PropsB>) -> DomTree {
|
||||
let (first, last) = cx.val.split_at(3);
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
@@ -64,7 +64,7 @@ mod components {
|
||||
val: String,
|
||||
}
|
||||
|
||||
fn CustomC(cx: Context<PropsC>) -> VNode {
|
||||
fn CustomC(cx: Context<PropsC>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
class: "m-8"
|
||||
|
||||
@@ -9,7 +9,7 @@ fn main() {
|
||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App))
|
||||
}
|
||||
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
fn App(cx: Context<()>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div { class: "dark:bg-gray-800 bg-white relative h-screen"
|
||||
NavBar {}
|
||||
@@ -18,7 +18,7 @@ fn App(cx: Context<()>) -> VNode {
|
||||
})
|
||||
}
|
||||
|
||||
fn NavBar(cx: Context<()>) -> VNode {
|
||||
fn NavBar(cx: Context<()>) -> DomTree {
|
||||
cx.render(rsx!{
|
||||
header { class: "h-24 sm:h-32 flex items-center z-30 w-full"
|
||||
div { class: "container mx-auto px-6 flex items-center justify-between"
|
||||
@@ -58,7 +58,7 @@ fn NavBar(cx: Context<()>) -> VNode {
|
||||
})
|
||||
}
|
||||
|
||||
fn Landing(cx: Context<()>) -> VNode {
|
||||
fn Landing(cx: Context<()>) -> DomTree {
|
||||
cx.render(rsx!{
|
||||
div { class: "bg-white dark:bg-gray-800 flex relative z-20 items-center"
|
||||
div { class: "container mx-auto px-6 flex flex-col justify-between items-center relative py-8"
|
||||
|
||||
@@ -9,7 +9,7 @@ fn main() {
|
||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
|
||||
}
|
||||
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
fn App(cx: Context<()>) -> DomTree {
|
||||
let cansee = use_state(cx, || false);
|
||||
rsx! { in cx,
|
||||
div {
|
||||
@@ -22,7 +22,7 @@ fn App(cx: Context<()>) -> VNode {
|
||||
}
|
||||
}
|
||||
|
||||
fn Child(cx: Context<()>) -> VNode {
|
||||
fn Child(cx: Context<()>) -> DomTree {
|
||||
rsx! { in cx,
|
||||
section { class: "py-6 bg-coolGray-100 text-coolGray-900"
|
||||
div { class: "container mx-auto flex flex-col items-center justify-center p-4 space-y-8 md:p-10 md:px-24 xl:px-48"
|
||||
|
||||
@@ -6,7 +6,7 @@ fn main() {
|
||||
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
|
||||
}
|
||||
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
fn App(cx: Context<()>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div { "Hello, world!" }
|
||||
})
|
||||
|
||||
@@ -132,7 +132,7 @@ static App: FC<()> = |cx| {
|
||||
))
|
||||
};
|
||||
|
||||
pub fn FilterToggles(cx: Context<()>) -> VNode {
|
||||
pub fn FilterToggles(cx: Context<()>) -> DomTree {
|
||||
// let reducer = recoil::use_callback(&cx, || ());
|
||||
// let items_left = recoil::use_atom_family(&cx, &TODOS, uuid::Uuid::new_v4());
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(JonsFavoriteCustomApp));
|
||||
}
|
||||
|
||||
fn JonsFavoriteCustomApp(cx: Context<()>) -> VNode {
|
||||
fn JonsFavoriteCustomApp(cx: Context<()>) -> DomTree {
|
||||
let items = (0..20).map(|f| {
|
||||
rsx! {
|
||||
li {"{f}"}
|
||||
|
||||
@@ -78,7 +78,7 @@ struct CalculatorKeyProps<'a> {
|
||||
onclick: &'a dyn Fn(MouseEvent),
|
||||
}
|
||||
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> VNode<'a> {
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
class: "calculator-key {cx.name}"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// wasm_bindgen_futures::spawn_local(WebsysRenderer::start(Example));
|
||||
// }
|
||||
|
||||
// fn Example(cx: Context, props: ()) -> VNode {
|
||||
// fn Example(cx: Context, props: ()) -> DomTree {
|
||||
// let user_data = use_sql_query(&cx, USER_DATA_QUERY);
|
||||
|
||||
// cx.render(rsx! {
|
||||
|
||||
@@ -57,7 +57,7 @@ struct ButtonProps<'src, F: Fn(MouseEvent)> {
|
||||
handler: F,
|
||||
}
|
||||
|
||||
fn CustomButton<'a, F: Fn(MouseEvent)>(cx: Context<'a, ButtonProps<'a, F>>) -> VNode {
|
||||
fn CustomButton<'a, F: Fn(MouseEvent)>(cx: Context<'a, ButtonProps<'a, F>>) -> DomTree {
|
||||
cx.render(rsx!{
|
||||
button {
|
||||
class: "inline-block py-4 px-8 mr-6 leading-none text-white bg-indigo-600 hover:bg-indigo-900 font-semibold rounded shadow"
|
||||
@@ -77,7 +77,7 @@ impl<F: Fn(MouseEvent)> PartialEq for ButtonProps<'_, F> {
|
||||
struct PlaceholderProps {
|
||||
val: &'static str,
|
||||
}
|
||||
fn Placeholder(cx: Context<PlaceholderProps>) -> VNode {
|
||||
fn Placeholder(cx: Context<PlaceholderProps>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
"child: {cx.val}"
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct TodoItem {
|
||||
pub contents: String,
|
||||
}
|
||||
|
||||
pub fn App(cx: Context<()>) -> VNode {
|
||||
pub fn App(cx: Context<()>) -> DomTree {
|
||||
let (draft, set_draft) = use_state_classic(cx, || "".to_string());
|
||||
let (todos, set_todos) = use_state_classic(cx, || HashMap::<uuid::Uuid, Rc<TodoItem>>::new());
|
||||
let (filter, set_filter) = use_state_classic(cx, || FilterState::All);
|
||||
@@ -99,7 +99,7 @@ pub struct TodoEntryProps {
|
||||
item: Rc<TodoItem>,
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> VNode {
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> DomTree {
|
||||
let (is_editing, set_is_editing) = use_state_classic(cx, || false);
|
||||
let contents = "";
|
||||
let todo = TodoItem {
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::recoil;
|
||||
use crate::state::{FilterState, TODOS};
|
||||
use dioxus_core::prelude::*;
|
||||
|
||||
pub fn FilterToggles(cx: Context<()>) -> VNode {
|
||||
pub fn FilterToggles(cx: Context<()>) -> DomTree {
|
||||
let reducer = recoil::use_callback(&cx, || ());
|
||||
let items_left = recoil::use_atom_family(&cx, &TODOS, uuid::Uuid::new_v4());
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ pub struct TodoEntryProps {
|
||||
id: uuid::Uuid,
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context, props: &TodoEntryProps) -> VNode {
|
||||
pub fn TodoEntry(cx: Context, props: &TodoEntryProps) -> DomTree {
|
||||
let (is_editing, set_is_editing) = use_state(cx, || false);
|
||||
let todo = use_atom_family(&cx, &TODOS, cx.id);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
};
|
||||
use dioxus_core::prelude::*;
|
||||
|
||||
pub fn TodoList(cx: Context<()>) -> VNode {
|
||||
pub fn TodoList(cx: Context<()>) -> DomTree {
|
||||
let (draft, set_draft) = use_state(cx, || "".to_string());
|
||||
let (todos, _) = use_state(cx, || Vec::<TodoItem>::new());
|
||||
let filter = use_atom(&cx, &FILTER);
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct TodoItem {
|
||||
// =======================
|
||||
// Components
|
||||
// =======================
|
||||
pub fn App(cx: Context<()>) -> VNode {
|
||||
pub fn App(cx: Context<()>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
id: "app"
|
||||
@@ -53,7 +53,7 @@ pub fn App(cx: Context<()>) -> VNode {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn TodoList(cx: Context<()>) -> VNode {
|
||||
pub fn TodoList(cx: Context<()>) -> DomTree {
|
||||
let (draft, set_draft) = use_state_classic(cx, || "".to_string());
|
||||
let (todos, set_todos) = use_state_classic(cx, || HashMap::<uuid::Uuid, Rc<TodoItem>>::new());
|
||||
let (filter, set_filter) = use_state_classic(cx, || FilterState::All);
|
||||
@@ -102,7 +102,7 @@ pub struct TodoEntryProps {
|
||||
item: Rc<TodoItem>,
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> VNode {
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> DomTree {
|
||||
let (is_editing, set_is_editing) = use_state_classic(cx, || false);
|
||||
let contents = "";
|
||||
let todo = TodoItem {
|
||||
@@ -128,7 +128,7 @@ pub fn TodoEntry(cx: Context<TodoEntryProps>) -> VNode {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn FilterToggles(cx: Context<()>) -> VNode {
|
||||
pub fn FilterToggles(cx: Context<()>) -> DomTree {
|
||||
let toggles = [
|
||||
("All", "", FilterState::All),
|
||||
("Active", "active", FilterState::Active),
|
||||
|
||||
@@ -73,7 +73,7 @@ impl TodoManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn TodoList(cx: Context<()>) -> VNode {
|
||||
pub fn TodoList(cx: Context<()>) -> DomTree {
|
||||
let draft = use_state(cx, || "".to_string());
|
||||
let todos = use_read(&cx, &TODO_LIST);
|
||||
let filter = use_read(&cx, &FILTER);
|
||||
@@ -117,7 +117,7 @@ pub struct TodoEntryProps {
|
||||
id: Uuid,
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context, props: &TodoEntryProps) -> VNode {
|
||||
pub fn TodoEntry(cx: Context, props: &TodoEntryProps) -> DomTree {
|
||||
let (is_editing, set_is_editing) = use_state_classic(cx, || false);
|
||||
let todo = use_read(&cx, &TODO_LIST).get(&cx.id).unwrap();
|
||||
|
||||
@@ -138,7 +138,7 @@ pub fn TodoEntry(cx: Context, props: &TodoEntryProps) -> VNode {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn FilterToggles(cx: Context<()>) -> VNode {
|
||||
pub fn FilterToggles(cx: Context<()>) -> DomTree {
|
||||
let reducer = TodoManager(use_recoil_api(cx));
|
||||
let items_left = use_read(cx, &TODOS_LEFT);
|
||||
|
||||
@@ -167,7 +167,7 @@ pub fn FilterToggles(cx: Context<()>) -> VNode {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Footer(cx: Context<()>) -> VNode {
|
||||
pub fn Footer(cx: Context<()>) -> DomTree {
|
||||
rsx! { in cx,
|
||||
footer { class: "info"
|
||||
p {"Double-click to edit a todo"}
|
||||
@@ -185,7 +185,7 @@ pub fn Footer(cx: Context<()>) -> VNode {
|
||||
|
||||
const APP_STYLE: &'static str = include_str!("./todomvc/style.css");
|
||||
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
fn App(cx: Context<()>) -> DomTree {
|
||||
use_init_recoil_root(cx, |_| {});
|
||||
rsx! { in cx,
|
||||
div { id: "app"
|
||||
|
||||
@@ -123,7 +123,7 @@ struct CalculatorKeyProps<'a> {
|
||||
onclick: &'a dyn Fn(MouseEvent),
|
||||
}
|
||||
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> VNode<'a> {
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
class: "calculator-key {cx.name}"
|
||||
@@ -138,7 +138,7 @@ struct CalculatorDisplayProps {
|
||||
val: f64,
|
||||
}
|
||||
|
||||
fn CalculatorDisplay(cx: Context<CalculatorDisplayProps>) -> VNode {
|
||||
fn CalculatorDisplay(cx: Context<CalculatorDisplayProps>) -> DomTree {
|
||||
use separator::Separatable;
|
||||
// Todo, add float support to the num-format crate
|
||||
let formatted = cx.val.separated_string();
|
||||
|
||||
@@ -66,7 +66,7 @@ struct CalculatorKeyProps<'a> {
|
||||
onclick: &'a dyn Fn(MouseEvent),
|
||||
}
|
||||
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> VNode<'a> {
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
class: "calculator-key {cx.name}"
|
||||
|
||||
@@ -92,7 +92,7 @@ struct ActionButtonProps<F: Fn(MouseEvent)> {
|
||||
id: &'static str,
|
||||
action: F,
|
||||
}
|
||||
fn ActionButton<F>(cx: Context<ActionButtonProps<F>>) -> VNode
|
||||
fn ActionButton<F>(cx: Context<ActionButtonProps<F>>) -> DomTree
|
||||
where
|
||||
F: Fn(MouseEvent),
|
||||
{
|
||||
@@ -110,7 +110,7 @@ struct RowProps {
|
||||
row_id: usize,
|
||||
label: Rc<str>,
|
||||
}
|
||||
fn Row<'a>(cx: Context<'a, RowProps>) -> VNode {
|
||||
fn Row<'a>(cx: Context<'a, RowProps>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
tr {
|
||||
td { class:"col-md-1", "{cx.row_id}" }
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ struct CalculatorKeyProps<'a> {
|
||||
onclick: &'a dyn Fn(MouseEvent),
|
||||
}
|
||||
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> VNode<'a> {
|
||||
fn CalculatorKey<'a, 'r>(cx: Context<'a, CalculatorKeyProps<'r>>) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
class: "calculator-key {cx.name}"
|
||||
|
||||
@@ -63,7 +63,7 @@ pub struct MyProps3<'a> {
|
||||
// We need to manually specify a lifetime that ensures props and scope (the component's state) share the same lifetime.
|
||||
// Using the `pub static Example: FC<()>` pattern _will_ specify a lifetime, but that lifetime will be static which might
|
||||
// not exactly be what you want
|
||||
fn Example3<'a>(cx: Context<'a, MyProps3<'a>>) -> VNode {
|
||||
fn Example3<'a>(cx: Context<'a, MyProps3<'a>>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div { "Not memoized! {cx.name}" }
|
||||
})
|
||||
@@ -77,7 +77,7 @@ pub struct MyProps4<'a> {
|
||||
}
|
||||
|
||||
// We need to manually specify a lifetime that ensures props and scope (the component's state) share the same lifetime.
|
||||
fn Example4<'a>(cx: Context<'a, MyProps4<'a>>) -> VNode {
|
||||
fn Example4<'a>(cx: Context<'a, MyProps4<'a>>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div { "Not memoized!", onclick: move |_| (cx.onhandle)() }
|
||||
})
|
||||
|
||||
@@ -183,7 +183,7 @@ mod baller {
|
||||
pub struct BallerProps {}
|
||||
|
||||
/// This component totally balls
|
||||
pub fn Baller(cx: Context<()>) -> VNode {
|
||||
pub fn Baller(cx: Context<()>) -> DomTree {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ pub struct TallerProps {
|
||||
}
|
||||
|
||||
/// This component is taller than most :)
|
||||
pub fn Taller(cx: Context<TallerProps>) -> VNode {
|
||||
pub fn Taller(cx: Context<TallerProps>) -> DomTree {
|
||||
let b = true;
|
||||
todo!()
|
||||
}
|
||||
@@ -33,7 +33,7 @@ struct ScrollSelectorProps<'a> {
|
||||
onselect: &'a dyn Fn(Option<usize>),
|
||||
}
|
||||
|
||||
fn ScrollSelector<'a>(cx: Context<'a, ScrollSelectorProps>) -> VNode<'a> {
|
||||
fn ScrollSelector<'a>(cx: Context<'a, ScrollSelectorProps>) -> DomTree<'a> {
|
||||
let selection_list = (&REFERENCES).iter().enumerate().map(|(id, _)| {
|
||||
rsx! {
|
||||
li {
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ pub struct TodoEntryProps {
|
||||
todo: std::rc::Rc<TodoItem>,
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> VNode {
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> DomTree {
|
||||
let TodoEntryProps { todo } = *cx;
|
||||
let is_editing = use_state(cx, || false);
|
||||
let contents = "";
|
||||
|
||||
Reference in new issue
Block a user