fix components that take no arguments
This commit is contained in:
1 parent
404c864246
commit
1794debf79
24 files changed
+98
-78
No files matched your search
@@ -23,7 +23,7 @@ fn attrs_cycle() {
|
||||
let bump = Bump::new();
|
||||
|
||||
assert_eq!(
|
||||
dom.rebuild_to_vec_to_vec().santize().edits,
|
||||
dom.rebuild_to_vec().santize().edits,
|
||||
[
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
||||
AppendChildren { m: 1, id: ElementId(0) },
|
||||
|
||||
@@ -21,7 +21,7 @@ fn test_borrowed_state() {
|
||||
);
|
||||
}
|
||||
|
||||
fn Parent(cx: Scope) -> Element {
|
||||
fn Parent() -> Element {
|
||||
let w1 = cx.use_hook(|| String::from("w1"));
|
||||
|
||||
render! {
|
||||
@@ -34,11 +34,11 @@ struct ChildProps<'a> {
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
||||
fn Child<'a>(cx: ChildProps) -> Element {
|
||||
render! {
|
||||
div {
|
||||
h1 { "it's nested" }
|
||||
Child2 { name: cx.props.name }
|
||||
Child2 { name: cx.name }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,6 @@ struct Grandchild<'a> {
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
fn Child2<'a>(cx: Scope<'a, Grandchild<'a>>) -> Element {
|
||||
render!( div { "Hello {cx.props.name}!" } )
|
||||
fn Child2<'a>(cx: Grandchild) -> Element {
|
||||
render!( div { "Hello {cx.name}!" } )
|
||||
}
|
||||
@@ -9,11 +9,11 @@ fn state_shares() {
|
||||
render!(child_1 {})
|
||||
}
|
||||
|
||||
fn child_1(cx: Scope) -> Element {
|
||||
fn child_1() -> Element {
|
||||
render!(child_2 {})
|
||||
}
|
||||
|
||||
fn child_2(cx: Scope) -> Element {
|
||||
fn child_2() -> Element {
|
||||
let value = cx.consume_context::<i32>().unwrap();
|
||||
render!("Value is {value}")
|
||||
}
|
||||
|
||||
@@ -134,10 +134,10 @@ fn create_components() {
|
||||
children: Element,
|
||||
}
|
||||
|
||||
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
||||
fn Child<'a>(cx: ChildProps) -> Element {
|
||||
render! {
|
||||
h1 {}
|
||||
div { &cx.props.children }
|
||||
div { &cx.children }
|
||||
p {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ fn fragments_across_components() {
|
||||
}
|
||||
}
|
||||
|
||||
fn demo_child(cx: Scope) -> Element {
|
||||
fn demo_child() -> Element {
|
||||
let world = "world";
|
||||
render! { "hellO!", world }
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use dioxus_core::ElementId;
|
||||
/// Should push the text node onto the stack and modify it
|
||||
#[test]
|
||||
fn nested_passthru_creates() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
render! {
|
||||
PassThru {
|
||||
@@ -17,7 +16,7 @@ fn nested_passthru_creates() {
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn PassThru<'a>(cx: Scope<'a>, children: Element) -> Element {
|
||||
fn PassThru<'a>(children: Element) -> Element {
|
||||
render!(children)
|
||||
}
|
||||
|
||||
@@ -38,7 +37,6 @@ fn nested_passthru_creates() {
|
||||
/// Take note on how we don't spit out the template for child_comp since it's entirely dynamic
|
||||
#[test]
|
||||
fn nested_passthru_creates_add() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
render! {
|
||||
ChildComp {
|
||||
@@ -55,7 +53,7 @@ fn nested_passthru_creates_add() {
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ChildComp<'a>(cx: Scope, children: Element) -> Element {
|
||||
fn ChildComp<'a>(children: Element) -> Element {
|
||||
render! {children}
|
||||
}
|
||||
|
||||
@@ -80,7 +78,6 @@ fn nested_passthru_creates_add() {
|
||||
/// note that the template is all dynamic roots - so it doesn't actually get cached as a template
|
||||
#[test]
|
||||
fn dynamic_node_as_root() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
let a = 123;
|
||||
let b = 456;
|
||||
|
||||
@@ -37,21 +37,21 @@ fn component_swap() {
|
||||
}
|
||||
}
|
||||
|
||||
fn nav_bar(cx: Scope) -> Element {
|
||||
fn nav_bar() -> Element {
|
||||
render! {
|
||||
h1 { "NavBar", (0..3).map(|_| render!(nav_link {})) }
|
||||
}
|
||||
}
|
||||
|
||||
fn nav_link(cx: Scope) -> Element {
|
||||
fn nav_link() -> Element {
|
||||
render!( h1 { "nav_link" } )
|
||||
}
|
||||
|
||||
fn dash_board(cx: Scope) -> Element {
|
||||
fn dash_board() -> Element {
|
||||
render!( div { "dashboard" } )
|
||||
}
|
||||
|
||||
fn dash_results(cx: Scope) -> Element {
|
||||
fn dash_results() -> Element {
|
||||
render!( div { "results" } )
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ fn app() -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
fn NoneChild(_cx: Scope) -> Element {
|
||||
fn NoneChild(_) -> Element {
|
||||
None
|
||||
}
|
||||
|
||||
fn ThrowChild(cx: Scope) -> Element {
|
||||
fn ThrowChild() -> Element {
|
||||
Err(std::io::Error::new(std::io::ErrorKind::AddrInUse, "asd")).throw()?;
|
||||
|
||||
let _g: i32 = "123123".parse().throw()?;
|
||||
|
||||
@@ -67,7 +67,7 @@ fn app() -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
fn problematic_child(cx: Scope) -> Element {
|
||||
fn problematic_child() -> Element {
|
||||
render! {
|
||||
button { onclick: move |evt| {
|
||||
println!("bottom clicked");
|
||||
|
||||
@@ -238,10 +238,10 @@ struct BorrowedDepthProps<'a> {
|
||||
inner: DepthProps,
|
||||
}
|
||||
|
||||
fn create_random_element_borrowed<'a>(cx: Scope<'a, BorrowedDepthProps<'a>>) -> Element {
|
||||
println!("{}", cx.props.borrow);
|
||||
fn create_random_element_borrowed<'a>(cx: BorrowedDepthProps) -> Element {
|
||||
println!("{}", cx.borrow);
|
||||
let bump = cx.bump();
|
||||
let allocated = bump.alloc(Scoped { scope: cx, props: &cx.props.inner });
|
||||
let allocated = bump.alloc(Scoped { scope: cx, props: &cx.inner });
|
||||
create_random_element(allocated)
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
|
||||
if rand::random::<usize>() % 10 == 0 {
|
||||
cx.needs_update();
|
||||
}
|
||||
let range = if cx.props.root { 2 } else { 3 };
|
||||
let range = if cx.root { 2 } else { 3 };
|
||||
let node = match rand::random::<usize>() % range {
|
||||
0 | 1 => {
|
||||
let (template, dynamic_node_types) = create_random_template(Box::leak(
|
||||
@@ -283,9 +283,7 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
|
||||
DynamicNodeType::Text => DynamicNode::Text(VText::new(Box::leak(
|
||||
format!("{}", rand::random::<usize>()).into_boxed_str(),
|
||||
))),
|
||||
DynamicNodeType::Other => {
|
||||
create_random_dynamic_node(cx, cx.props.depth + 1)
|
||||
}
|
||||
DynamicNodeType::Other => create_random_dynamic_node(cx, cx.depth + 1),
|
||||
})
|
||||
.collect();
|
||||
cx.bump().alloc(dynamic_nodes)
|
||||
|
||||
@@ -2,7 +2,7 @@ use bumpalo::Bump;
|
||||
use dioxus::core::{ElementId, Mutation};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn basic_syntax_is_a_template(cx: Scope) -> Element {
|
||||
fn basic_syntax_is_a_template() -> Element {
|
||||
let asd = 123;
|
||||
let var = 123;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ fn manual_diffing() {
|
||||
}
|
||||
|
||||
fn app(cx: Scope<AppProps>) -> Element {
|
||||
let val = cx.props.value.lock().unwrap();
|
||||
let val = cx.value.lock().unwrap();
|
||||
render! { div { "{val}" } }
|
||||
};
|
||||
|
||||
@@ -96,7 +96,7 @@ fn events_generate() {
|
||||
// })
|
||||
// };
|
||||
|
||||
// fn Child(cx: Scope) -> Element {
|
||||
// fn Child() -> Element {
|
||||
// println!("Running child");
|
||||
// render_without_templates! {
|
||||
// h1 {}
|
||||
|
||||
@@ -25,7 +25,7 @@ fn miri_rollover() {
|
||||
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
let mut idx = use_state(cx, || 0);
|
||||
let mut idx = use_signal(|| 0);
|
||||
let onhover = |_| println!("go!");
|
||||
|
||||
render! {
|
||||
@@ -48,6 +48,6 @@ fn App() -> Element {
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ChildExample<'a>(cx: Scope<'a>, i: i32, onhover: EventHandler<'a, MouseEvent>) -> Element {
|
||||
fn ChildExample<'a>(i: i32, onhover: EventHandler<'a, MouseEvent>) -> Element {
|
||||
render! { li { onmouseover: move |e| onhover.call(e), "{i}" } }
|
||||
}
|
||||
@@ -2,7 +2,6 @@ use dioxus::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn app_drops() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
render! { div {} }
|
||||
}
|
||||
@@ -16,7 +15,6 @@ fn app_drops() {
|
||||
|
||||
#[test]
|
||||
fn hooks_drop() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
cx.use_hook(|| String::from("asd"));
|
||||
cx.use_hook(|| String::from("asd"));
|
||||
@@ -35,7 +33,6 @@ fn hooks_drop() {
|
||||
|
||||
#[test]
|
||||
fn contexts_drop() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
cx.provide_context(String::from("asd"));
|
||||
|
||||
@@ -45,7 +42,7 @@ fn contexts_drop() {
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ChildComp(cx: Scope) -> Element {
|
||||
fn ChildComp() -> Element {
|
||||
let el = cx.consume_context::<String>().unwrap();
|
||||
|
||||
render! { div { "hello {el}" } }
|
||||
@@ -60,7 +57,6 @@ fn contexts_drop() {
|
||||
|
||||
#[test]
|
||||
fn tasks_drop() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
cx.spawn(async {
|
||||
// tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
|
||||
@@ -81,7 +77,7 @@ fn root_props_drop() {
|
||||
struct RootProps(String);
|
||||
|
||||
let mut dom = VirtualDom::new_with_props(
|
||||
|cx| render!( div { "{cx.props.0}" } ),
|
||||
|cx| render!( div { "{cx.0}" } ),
|
||||
RootProps("asdasd".to_string()),
|
||||
);
|
||||
|
||||
@@ -92,7 +88,6 @@ fn root_props_drop() {
|
||||
|
||||
#[test]
|
||||
fn diffing_drops_old() {
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
render! {
|
||||
div {
|
||||
@@ -106,12 +101,12 @@ fn diffing_drops_old() {
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ChildComp1(cx: Scope, name: String) -> Element {
|
||||
fn ChildComp1(name: String) -> Element {
|
||||
render! {"Hello {name}"}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ChildComp2(cx: Scope, name: String) -> Element {
|
||||
fn ChildComp2(name: String) -> Element {
|
||||
render! {"Goodbye {name}"}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,22 +38,22 @@ fn test_memory_leak() {
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Props)]
|
||||
struct BorrowedProps<'a> {
|
||||
name: &'a str,
|
||||
#[derive(Props, Clone, PartialEq)]
|
||||
struct BorrowedProps {
|
||||
name: String,
|
||||
}
|
||||
|
||||
fn BorrowedChild<'a>(cx: Scope<'a, BorrowedProps<'a>>) -> Element {
|
||||
fn BorrowedChild(cx: BorrowedProps) -> Element {
|
||||
render! {
|
||||
div {
|
||||
"goodbye {cx.props.name}"
|
||||
"goodbye {cx.name}"
|
||||
Child {}
|
||||
Child {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn Child(cx: Scope) -> Element {
|
||||
fn Child() -> Element {
|
||||
render!( div { "goodbye world" } )
|
||||
}
|
||||
|
||||
@@ -117,12 +117,12 @@ fn free_works_on_root_hooks() {
|
||||
}
|
||||
|
||||
fn app(cx: Scope<AppProps>) -> Element {
|
||||
let name: &AppProps = cx.use_hook(|| cx.props.clone());
|
||||
let name: &AppProps = cx.use_hook(|| cx.clone());
|
||||
render!(child_component { inner: name.inner.clone() })
|
||||
}
|
||||
|
||||
fn child_component(cx: Scope<AppProps>) -> Element {
|
||||
render!( div { "{cx.props.inner}" } )
|
||||
render!( div { "{cx.inner}" } )
|
||||
}
|
||||
|
||||
let ptr = Rc::new("asdasd".to_string());
|
||||
@@ -143,8 +143,8 @@ fn supports_async() {
|
||||
use tokio::time::sleep;
|
||||
|
||||
fn app() -> Element {
|
||||
let colors = use_state(cx, || vec!["green", "blue", "red"]);
|
||||
let padding = use_state(cx, || 10);
|
||||
let colors = use_signal(|| vec!["green", "blue", "red"]);
|
||||
let padding = use_signal(|| 10);
|
||||
|
||||
use_effect(cx, colors, |colors| async move {
|
||||
sleep(Duration::from_millis(1000)).await;
|
||||
|
||||
@@ -28,11 +28,10 @@ fn app() -> Element {
|
||||
)
|
||||
}
|
||||
|
||||
fn suspended_child(cx: Scope) -> Element {
|
||||
let val = use_state(cx, || 0);
|
||||
fn suspended_child() -> Element {
|
||||
let mut val = use_signal(|| 0);
|
||||
|
||||
if **val < 3 {
|
||||
let mut val = val.clone();
|
||||
if *val() < 3 {
|
||||
cx.spawn(async move {
|
||||
val += 1;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user