diff --git a/README.md b/README.md index 1ac03771b..7fc5ccf13 100644 --- a/README.md +++ b/README.md @@ -23,30 +23,24 @@ - CI status

- - API Docs - + Guide | - - Website - + Website | - - Examples - + Examples


-Dioxus is a portable, performant, and ergonomic framework for building cross-platform user experiences in Rust. +Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust. ```rust fn app(cx: Scope) -> Element { @@ -67,29 +61,29 @@ If you know React, then you already know Dioxus. ### Unique features: - Desktop apps running natively (no Electron!) in less than 10 lines of code. - Incredibly ergonomic and powerful state management. -- Incredible inline documentation - hover and guides for all HTML elements, listeners, and events. +- Comprehensive inline documentation - hover and guides for all HTML elements, listeners, and events. - Extremely memory efficient - 0 global allocations for steady-state components. -- Multithreaded asynchronous coroutine scheduler for first-class async support. -- And more! Read the full release post here. +- Multi-channel asynchronous scheduler for first-class async support. +- And more! Read the [full release post here](https://dioxuslabs.com/). ## Get Started with... - - - - - - + + + + + +
WebDesktopMobileStateDocsToolsWebDesktopMobileStateDocsTools
## Examples: -| File Navigator (Desktop) | Bluetooth scanner (Desktop) | TodoMVC (All platforms) | Tailwind (Liveview) | -| --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -| [![asd](https://github.com/DioxusLabs/file-explorer-example/raw/master/image.png)](https://github.com/DioxusLabs/file-explorer-example) | [![asd](https://github.com/DioxusLabs/file-explorer-example/raw/master/image.png)](https://github.com/DioxusLabs/file-explorer-example) | [![asd](https://github.com/DioxusLabs/todomvc/raw/master/example.png)](https://github.com/dioxusLabs/todomvc/) | [![asd](https://github.com/DioxusLabs/file-explorer-example/raw/master/image.png)](https://github.com/DioxusLabs/file-explorer-example) | +| File Navigator (Desktop) | WiFi scanner (Desktop) | TodoMVC (All platforms) | Tailwind (Liveview) | +| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | +| [![asd](https://github.com/DioxusLabs/file-explorer-example/raw/master/image.png)](https://github.com/DioxusLabs/file-explorer-example) | [![Wifi Scanner Demo](https://github.com/DioxusLabs/wifi-scanner/raw/master/demo_small.png)](https://github.com/DioxusLabs/wifi-scanner) | [![TodoMVC example](https://github.com/DioxusLabs/todomvc/raw/master/example.png)](https://github.com/dioxusLabs/todomvc/) | [![Ecommerce Example](https://github.com/DioxusLabs/ecommerce-example/blob/master/demo.png)](https://github.com/DioxusLabs/ecommerce-example) | See the awesome-dioxus page for a curated list of content in the Dioxus Ecosystem. @@ -182,7 +176,7 @@ Dioxus is heavily inspired by React, but we want your transition to feel like an This project is licensed under the [MIT license]. -[MIT license]: https://github.com/tokio-rs/tokio/blob/master/LICENSE +[MIT license]: https://github.com/dioxuslabs/dioxus/blob/master/LICENSE ### Contribution diff --git a/docs/guide/src/concepts/06-subscription-api.md b/docs/guide/src/concepts/06-subscription-api.md index af143e03b..19ec66563 100644 --- a/docs/guide/src/concepts/06-subscription-api.md +++ b/docs/guide/src/concepts/06-subscription-api.md @@ -3,7 +3,7 @@ Yew subscriptions are used to schedule update for components into the future. The `Context` object can create subscriptions: ```rust -fn Component(cx: Component<()>) -> DomTree { +fn Component(cx: Component) -> DomTree { let update = cx.schedule(); // Now, when the subscription is called, the component will be re-evaluated diff --git a/docs/guide/src/concepts/11-arena-memo.md b/docs/guide/src/concepts/11-arena-memo.md index d1b78322c..d95a67d19 100644 --- a/docs/guide/src/concepts/11-arena-memo.md +++ b/docs/guide/src/concepts/11-arena-memo.md @@ -21,9 +21,9 @@ fn test() -> DomTree { } } -static TestComponent: Component<()> = |cx| html!{
"Hello world"
}; +static TestComponent: Component = |cx| html!{
"Hello world"
}; -static TestComponent: Component<()> = |cx|{ +static TestComponent: Component = |cx|{ let g = "BLAH"; html! {
"Hello world"
diff --git a/docs/guide/src/concepts/12-signals.md b/docs/guide/src/concepts/12-signals.md index 0e28baf03..051247475 100644 --- a/docs/guide/src/concepts/12-signals.md +++ b/docs/guide/src/concepts/12-signals.md @@ -96,7 +96,7 @@ Sometimes you want a signal to propagate across your app, either through far-awa ```rust const TITLE: Atom = || "".to_string(); -const Provider: Component<()> = |cx|{ +const Provider: Component = |cx|{ let title = use_signal(&cx, &TITLE); rsx!(cx, input { value: title }) }; @@ -105,7 +105,7 @@ const Provider: Component<()> = |cx|{ If we use the `TITLE` atom in another component, we can cause updates to flow between components without calling render or diffing either component trees: ```rust -const Receiver: Component<()> = |cx|{ +const Receiver: Component = |cx|{ let title = use_signal(&cx, &TITLE); log::info!("This will only be called once!"); rsx!(cx, @@ -132,7 +132,7 @@ Dioxus automatically understands how to use your signals when mixed with iterato ```rust const DICT: AtomFamily = |_| {}; -const List: Component<()> = |cx|{ +const List: Component = |cx|{ let dict = use_signal(&cx, &DICT); cx.render(rsx!( ul { diff --git a/docs/guide/src/concepts/conditional_rendering.md b/docs/guide/src/concepts/conditional_rendering.md index 61dcbe651..5bb75c490 100644 --- a/docs/guide/src/concepts/conditional_rendering.md +++ b/docs/guide/src/concepts/conditional_rendering.md @@ -83,7 +83,7 @@ fn App(cx: Scope)-> Element { This syntax even enables us to write a one-line component: ```rust -static App: Component<()> = |cx| rsx!(cx, "hello world!"); +static App: Component = |cx| rsx!(cx, "hello world!"); ``` Alternatively, for match statements, we can just return the builder itself and pass it into a final, single call to `cx.render`: diff --git a/docs/guide/src/concepts/errorhandling.md b/docs/guide/src/concepts/errorhandling.md index 091d9925c..40436521f 100644 --- a/docs/guide/src/concepts/errorhandling.md +++ b/docs/guide/src/concepts/errorhandling.md @@ -4,7 +4,7 @@ Astute observers might have noticed that `Element` is actually a type alias for `Option`. You don't need to know what a `VNode` is, but it's important to recognize that we could actually return nothing at all: ```rust -fn App((cx, props): Component<()>) -> Element { +fn App((cx, props): Component) -> Element { None } ``` diff --git a/docs/guide/src/concepts/exporting_components.md b/docs/guide/src/concepts/exporting_components.md index 6139a97e6..59fea7046 100644 --- a/docs/guide/src/concepts/exporting_components.md +++ b/docs/guide/src/concepts/exporting_components.md @@ -25,7 +25,7 @@ fn main() { dioxus::desktop::launch(App); } -fn App((cx, props): Component<()>) -> Element {} +fn App((cx, props): Component) -> Element {} #[derive(PartialEq, Props)] struct PostProps{} @@ -92,7 +92,7 @@ fn main() { mod post; -fn App((cx, props): Component<()>) -> Element { +fn App((cx, props): Component) -> Element { cx.render(rsx!{ post::Post { id: Uuid::new_v4(), @@ -191,7 +191,7 @@ fn main() { mod post; -fn App((cx, props): Component<()>) -> Element { +fn App((cx, props): Component) -> Element { cx.render(rsx!{ post::Post { id: Uuid::new_v4(), diff --git a/docs/guide/src/hello_world.md b/docs/guide/src/hello_world.md index 225c8603a..fd5e90aa5 100644 --- a/docs/guide/src/hello_world.md +++ b/docs/guide/src/hello_world.md @@ -135,7 +135,7 @@ fn App(cx: Scope) -> Element { Writing `fn App(cx: Scope) -> Element {` might become tedious. Rust will also let you write functions as static closures, but these types of Components cannot have props that borrow data. ```rust -static App: Component<()> = |cx| cx.render(rsx!(div { "Hello, world!" })); +static App: Component = |cx| cx.render(rsx!(div { "Hello, world!" })); ``` ### What is this `Context` object? diff --git a/examples/README.md b/examples/README.md index 2c05466a2..eabb0f57d 100644 --- a/examples/README.md +++ b/examples/README.md @@ -64,18 +64,18 @@ Here's what a few common tasks look like in Dioxus: Nested components with children and internal state: ```rust -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { cx.render(rsx!( Toggle { "Toggle me" } )) } #[derive(PartialEq, Props)] struct ToggleProps { children: Element } -fn Toggle(cx: Context, props: &ToggleProps) -> Element { +fn Toggle(cx: Scope) -> Element { let mut toggled = use_state(&cx, || false); cx.render(rsx!{ div { - {&props.children} + {&cx.props.children} button { onclick: move |_| toggled.set(true), {toggled.and_then(|| "On").or_else(|| "Off")} } @@ -86,7 +86,7 @@ fn Toggle(cx: Context, props: &ToggleProps) -> Element { Controlled inputs: ```rust -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { let value = use_state(&cx, String::new); cx.render(rsx!( input { @@ -100,7 +100,7 @@ fn App(cx: Context, props: &()) -> Element { Lists and Conditional rendering: ```rust -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { let list = (0..10).map(|i| { rsx!(li { key: "{i}", "Value: {i}" }) }); @@ -123,12 +123,12 @@ fn App(cx: Context, props: &()) -> Element { Tiny components: ```rust -static App: Component<()> = |cx, _| rsx!(cx, div {"hello world!"}); +static App: Component = |cx, _| rsx!(cx, div {"hello world!"}); ``` Borrowed prop contents: ```rust -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { let name = use_state(&cx, || String::from("example")); rsx!(cx, Child { title: name.as_str() }) } @@ -136,7 +136,7 @@ fn App(cx: Context, props: &()) -> Element { #[derive(Props)] struct ChildProps<'a> { title: &'a str } -fn Child(cx: Context, props: &ChildProps) -> Element { +fn Child(cx: Scope) -> Element { rsx!(cx, "Hello {cx.props.title}") } ``` @@ -145,12 +145,12 @@ Global State ```rust struct GlobalState { name: String } -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { use_provide_shared_state(cx, || GlobalState { name: String::from("Toby") }) rsx!(cx, Leaf {}) } -fn Leaf(cx: Context, props: &()) -> Element { +fn Leaf(cx: Scope<()>) -> Element { let state = use_consume_shared_state::(cx)?; rsx!(cx, "Hello {state.name}") } @@ -166,7 +166,7 @@ enum Route { Post(id) } -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { let route = use_router(cx, Route::parse); cx.render(rsx!(div { {match route { @@ -179,7 +179,7 @@ fn App(cx: Context, props: &()) -> Element { Suspense ```rust -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { let doggo = use_suspense(cx, || async { reqwest::get("https://dog.ceo/api/breeds/image/random").await.unwrap().json::().await.unwrap() }, |response| cx.render(rsx!( img { src: "{response.message}" })) diff --git a/examples/async.rs b/examples/async.rs index 8a7027882..c473ead72 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -11,7 +11,7 @@ async fn main() { dioxus::desktop::launch(App); } -pub static App: Component<()> = |cx| { +pub static App: Component = |cx| { let count = use_state(&cx, || 0); let mut direction = use_state(&cx, || 1); diff --git a/examples/calculator.rs b/examples/calculator.rs index 1b464f361..c7490a1b4 100644 --- a/examples/calculator.rs +++ b/examples/calculator.rs @@ -13,7 +13,7 @@ fn main() { dioxus::desktop::launch(APP); } -static APP: Component<()> = |cx| { +static APP: Component = |cx| { let cur_val = use_state(&cx, || 0.0_f64); let operator = use_state(&cx, || None as Option<&'static str>); let display_value = use_state(&cx, || String::from("")); diff --git a/examples/core/alternative.rs b/examples/core/alternative.rs index a009a88cb..219c603ee 100644 --- a/examples/core/alternative.rs +++ b/examples/core/alternative.rs @@ -9,13 +9,12 @@ fn main() { println!("{}", dom); } -pub static EXAMPLE: Component<()> = |cx| { +pub static EXAMPLE: Component = |cx| { let list = (0..10).map(|_f| { rsx! { "{_f}" } }); - // let list = (0..10).map(|_f| Some(Box::new(move |_f| todo!()))); cx.render(Some(LazyNodes::new(move |cx| { cx.raw_element( diff --git a/examples/core/async.rs b/examples/core/async.rs deleted file mode 100644 index 2919651d2..000000000 --- a/examples/core/async.rs +++ /dev/null @@ -1,15 +0,0 @@ -use dioxus_core::prelude::*; - -fn main() { - let mut dom = VirtualDom::new(App); - dom.rebuild(); -} - -const App: Component<()> = |cx| { - let id = cx.scope_id(); - // cx.submit_task(Box::pin(async move { id })); - - // let (handle, contents) = use_task(cx, || async { "hello world".to_string() }); - - todo!() -}; diff --git a/examples/core/borrowed.rs b/examples/core/borrowed.rs deleted file mode 100644 index 239d5c348..000000000 --- a/examples/core/borrowed.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! Demonstrate that borrowed data is possible as a property type -//! Borrowing (rather than cloning) is very important for speed and ergonomics. -//! -//! It's slightly more advanced than just cloning, but well worth the investment. -//! -//! If you use the FC macro, we handle the lifetimes automatically, making it easy to write efficient & performant components. -fn main() {} - -use dioxus_core::prelude::*; - -use std::rc::Rc; - -struct AppProps { - items: Vec>, -} - -#[derive(PartialEq)] -struct ListItem { - name: String, - age: u32, -} - -fn app<'a>(cx: Context<'a>, props: &AppProps) -> Element<'a> { - // let (val, set_val) = use_state_classic(cx, || 0); - - todo!() - // cx.render(LazyNodes::new(move |_nodecx| { - // todo!() - // // builder::ElementBuilder::new(_nodecx, "div") - // // .iter_child({ - // // cx.items.iter().map(|child| { - // // builder::virtual_child( - // // _nodecx, - // // ChildItem, - // // ChildProps { - // // item: child.clone(), - // // item_handler: set_val.clone(), - // // }, - // // None, - // // &[], - // // ) - // // }) - // // }) - // // .iter_child([builder::ElementBuilder::new(_nodecx, "div") - // // .iter_child([builder::text3(_nodecx.bump(), format_args!("{}", val))]) - // // .finish()]) - // // .finish() - // })) -} - -// props should derive a partialeq implementation automatically, but implement ptr compare for & fields -struct ChildProps { - // Pass down complex structs - item: Rc, - - // Even pass down handlers! - item_handler: Rc, -} - -fn ChildItem<'a>(cx: Context<'a>, props: &'a ChildProps) -> Element<'a> { - todo!() -} - -impl PartialEq for ChildProps { - fn eq(&self, _other: &Self) -> bool { - false - } -} -impl Properties for ChildProps { - type Builder = (); - const IS_STATIC: bool = true; - fn builder() -> Self::Builder { - () - } - unsafe fn memoize(&self, other: &Self) -> bool { - self == other - } -} diff --git a/examples/core/contextapi.rs b/examples/core/contextapi.rs deleted file mode 100644 index d538d49ae..000000000 --- a/examples/core/contextapi.rs +++ /dev/null @@ -1,36 +0,0 @@ -use dioxus_core::prelude::*; - -fn main() {} -struct SomeContext { - items: Vec, -} - -#[allow(unused)] -static Example: Component<()> = |cx| { - todo!() - - // let value = cx.use_context(|c: &SomeContext| c.items.last().unwrap()); - - // cx.render(LazyNodes::new(move |bump| { - // builder::ElementBuilder::new(bump, "button") - // .on("click", move |_| { - // println!("Value is {}", cx.name); - // println!("Value is {}", value.as_str()); - // println!("Value is {}", *value); - // }) - // .on("click", move |_| { - // println!("Value is {}", cx.name); - // }) - // .finish() - // })) - // cx.render(html! { - //
- //
- // }) -}; diff --git a/examples/core/expand.rs b/examples/core/expand.rs deleted file mode 100644 index 1b041b70c..000000000 --- a/examples/core/expand.rs +++ /dev/null @@ -1 +0,0 @@ -fn main( ) {} diff --git a/examples/core/fragment_from_iter.rs b/examples/core/fragment_from_iter.rs deleted file mode 100644 index 02f42b96d..000000000 --- a/examples/core/fragment_from_iter.rs +++ /dev/null @@ -1,46 +0,0 @@ -use dioxus_core::prelude::*; - -fn main() {} - -fn app<'a>(cx: Context<'a>, props: &()) -> Element<'a> { - // let vak = use_suspense( - // cx, - // || async {}, - // |c, _res| c.render(LazyNodes::new(move |f| f.text(format_args!("")))), - // ); - - // let d1 = cx.render(to_lazy_nodes(move |f| { - // f.raw_element( - // "div", - // None, - // [], - // [], - // [ - // // f.fragment_from_iter(vak), - // f.text(format_args!("")), - // f.text(format_args!("")), - // f.text(format_args!("")), - // f.text(format_args!("")), - // ], - // None, - // ) - // })); - - todo!() - // cx.render(LazyNodes::new(move |f| { - // f.raw_element( - // "div", - // None, - // [], - // [], - // [ - // f.text(format_args!("")), - // f.text(format_args!("")), - // f.text(format_args!("")), - // f.text(format_args!("")), - // d1.unwrap(), - // ], - // None, - // ) - // })) -} diff --git a/examples/core/syntax.rs b/examples/core/syntax.rs deleted file mode 100644 index 2339af8ad..000000000 --- a/examples/core/syntax.rs +++ /dev/null @@ -1,148 +0,0 @@ -use std::marker::PhantomData; - -use dioxus::component::Scope; -use dioxus::events::on::MouseEvent; -use dioxus::nodes::IntoVNode; -use dioxus_core as dioxus; -use dioxus_core::prelude::*; -use dioxus_core_macro::*; -use dioxus_html as dioxus_elements; - -fn main() {} - -fn html_usage() { - let mo = move |_| {}; - let r = rsx! { - div { - onclick: move |_| {} - onmouseover: {mo} - "type": "bar", - "hello world" - } - }; - - let items = ["bob", "bill", "jack"]; - - let f = items - .iter() - .filter(|f| f.starts_with('b')) - .map(|f| rsx!("hello {f}")); - - // let p = rsx!(div { {f} }); -} - -static App2: Component<()> = |cx, _| cx.render(rsx!("hello world!")); - -static App: Component<()> = |cx| { - let name = cx.use_state(|| 0); - - cx.render(rsx!(div { - h1 {} - h2 {} - })) -}; - -pub trait UseState<'a, T: 'static> { - fn use_state(self, f: impl FnOnce() -> T) -> &'a T; -} -impl<'a, T: 'static> UseState<'a, T> for Context<'a> { - fn use_state(self, f: impl FnOnce() -> T) -> &'a T { - todo!() - } -} - -fn App3((cx, props): Scope<()>) -> Element { - let p = rsx! { - Child { - bame: 10, - } - }; - todo!() - // cx.render(rsx!(Child { - // bame: 102, - // ..ChildProps { bame: 10 } - // })) -} - -#[derive(Props, PartialEq, Debug)] -struct ChildProps { - bame: i32, // children: Children<'a>, -} - -fn Child<'a>((cx, props): Scope<'a, ChildProps>) -> Element<'a> { - cx.render(rsx!(div { - // {cx.props.children} - })) -} - -// Some(LazyNodes::new(|f| { -// // -// // let r = f.fragment_from_iter(&props.children); -// r -// // todo!() -// })) -// todo!() -// rsx!({ Some(p) }) -// todo!() - -pub struct Children<'a> { - children: VNode<'static>, - _p: PhantomData<&'a ()>, -} - -impl<'a> Children<'a> { - pub fn new(children: VNode<'a>) -> Self { - Self { - children: unsafe { std::mem::transmute(children) }, - _p: PhantomData, - } - } -} - -static Bapp: Component<()> = |cx| { - let name = cx.use_state(|| 0); - - cx.render(rsx!( - div { - div { - - } - div { - - } - } - )) -}; - -static Match: Component<()> = |cx| { - // - let b: Box VNode> = Box::new(|f| todo!()); - - let b = match "ag" { - "a" => { - let __b: Box VNode> = Box::new(|f: NodeFactory| todo!()); - __b - } - _ => { - let __b: Box VNode> = Box::new(|f: NodeFactory| todo!()); - __b - } - }; - - // let b: Box VNode> = match "alph" { - // "beta" => Box::new(|f: NodeFactory| { - // // - // todo!() - // }), - // _ => Box::new(|f: NodeFactory| { - // // - // todo!() - // }), - // }; - - cx.render(rsx! { - div { - - } - }) -}; diff --git a/examples/core/syntax2.rs b/examples/core/syntax2.rs deleted file mode 100644 index 0b3a9e049..000000000 --- a/examples/core/syntax2.rs +++ /dev/null @@ -1,259 +0,0 @@ -use std::borrow::BorrowMut; -use std::cell::{Cell, RefCell}; -use std::marker::PhantomData; - -use dioxus::component::Scope; -use dioxus::events::on::MouseEvent; -use dioxus::nodes::{IntoVNode, VComponent, VFragment, VText}; -use dioxus_core as dioxus; -use dioxus_core::prelude::*; -use dioxus_core_macro::*; -use dioxus_html as dioxus_elements; - -fn main() {} - -fn t() { - let g = rsx! { - div { - div { - - } - } - }; - - let g = { - let ___p: Box VNode> = Box::new(|__cx: NodeFactory| { - use dioxus_elements::{GlobalAttributes, SvgAttributes}; - __cx.element(dioxus_elements::div, [], [], [], None) - }); - // let __z = ___p as ; - // __z - }; -} - -// #[derive(PartialEq, Props)] -// struct OurProps { -// foo: String, -// } - -// fn App<'a>((cx, props): Scope<'a, OurProps>) -> Element<'a> { -// let a = rsx! { -// div { -// "asd" -// "{cx.props.foo}" -// } -// }; - -// let p = (0..10).map(|f| { -// rsx! { -// div { - -// } -// } -// }); - -// let g = match "text" { -// "a" => { -// rsx!("asd") -// } -// _ => { -// rsx!("asd") -// } -// }; - -// let items = ["bob", "bill", "jack"]; - -// let f = items -// .iter() -// .filter(|f| f.starts_with('b')) -// .map(|f| rsx!("hello {f}")); - -// // use dioxus_hooks; -// // let g = use_state(|| "hello".to_string()); - -// let s: &'a mut String = cx.use_hook(|_| String::new(), |f| f, |_| {}); - -// /* -// the final closure is allowed to borrow anything provided it -// */ -// // cx.render({ -// // let p: Option _>> = Some(Box::new(move |__cx: NodeFactory| { -// // use dioxus_elements::{GlobalAttributes, SvgAttributes}; - -// // let props = Child2Props { foo: s }; -// // let ch: VNode = __cx.component(Child2, props, None, []); -// // __cx.element( -// // dioxus_elements::div, -// // [], -// // [], -// // [ch], -// // // [__cx.component(Child2, fc_to_builder(Child2).foo(s).build(), None, [])], -// // None, -// // ) -// // })); -// // p -// // // let ___p: Box VNode> = Box::new(move |__cx| { -// // // use dioxus_elements::{GlobalAttributes, SvgAttributes}; - -// // // let props = Child2Props { foo: s }; -// // // let ch: VNode = __cx.component(Child2, props, None, []); -// // // __cx.element( -// // // dioxus_elements::div, -// // // [], -// // // [], -// // // [ch], -// // // // [__cx.component(Child2, fc_to_builder(Child2).foo(s).build(), None, [])], -// // // None, -// // // ) -// // // }); -// // // Some(___p) -// // }) - -// let a = annotate_lazy(move |f| { -// // -// todo!() -// }); -// let b = annotate_lazy(move |f| { -// // -// f.text(format_args!("{}", props.foo)) -// }); - -// let c = annotate_lazy(move |f| { -// // -// f.component( -// Child, -// OurProps { -// // -// foo: "hello".to_string(), -// }, -// None, -// [], -// ) -// }); - -// let st: &'a String = cx.use_hook(|_| "hello".to_string(), |f| f, |_| {}); - -// let d = annotate_lazy(move |f| { -// // -// f.component( -// Child2, -// Child2Props { -// // -// foo: st, -// }, -// None, -// [], -// ) -// }); - -// let e = match "asd" { -// b => { -// // - -// annotate_lazy(move |f| { -// // -// f.text(format_args!("{}", props.foo)) -// }) -// } -// a => { -// // - -// annotate_lazy(move |f| { -// // -// f.text(format_args!("{}", props.foo)) -// }) -// } -// }; - -// cx.render(annotate_lazy(move |f| { -// // - -// f.raw_element( -// "div", -// None, -// [], -// [], -// [ -// // -// f.fragment_from_iter(a), -// f.fragment_from_iter(b), -// f.fragment_from_iter(c), -// f.fragment_from_iter(e), -// ], -// None, -// ) -// // todo!() -// })) -// // cx.render(rsx! { -// // div { -// // div { -// // {a} -// // // {p} -// // // {g} -// // // {f} -// // } -// // // div { -// // // "asd" -// // // div { -// // // "asd" -// // // } -// // // } -// // // Child { -// // // foo: "asd".to_string(), -// // // } -// // Child2 { -// // foo: s, -// // } -// // } -// // }) -// } - -// fn Child((cx, props): Scope) -> Element { -// cx.render(rsx! { -// div { -// div {} -// } -// }) -// } - -#[derive(Props)] -struct Child2Props<'a> { - foo: &'a String, -} - -fn Child2<'a>((cx, props): Scope<'a, Child2Props>) -> Element<'a> { - let node = cx - .render(rsx! { - div { - - } - }) - .unwrap(); - - cx.render(rsx! { - div { - ChildrenComp { - div {} - } - } - }) -} - -#[derive(Props)] -struct ChildrenTest<'a> { - children: ScopeChildren<'a>, -} - -fn ChildrenComp<'a>((cx, props): Scope<'a, ChildrenTest<'a>>) -> Element<'a> { - cx.render(rsx! { - div { - div { - {&props.children} - } - } - }) -} - -fn ChildrenMemo((cx, props): Scope<()>) -> Element { - todo!() -} diff --git a/examples/core/tasks.rs b/examples/core/tasks.rs deleted file mode 100644 index f328e4d9d..000000000 --- a/examples/core/tasks.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/examples/core/vdom_usage.rs b/examples/core/vdom_usage.rs deleted file mode 100644 index 844174062..000000000 --- a/examples/core/vdom_usage.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::time::Duration; - -use dioxus_core::{lazynodes::LazyNodes, prelude::*}; - -// #[async_std::main] -fn main() { - static App: Component<()> = - |cx, props| cx.render(Some(LazyNodes::new(move |f| f.text(format_args!("hello"))))); - - let mut dom = VirtualDom::new(App); - - dom.rebuild(); - - // let deadline = async_std::task::sleep(Duration::from_millis(50)); - - // let _fut = dom.run_with_deadline(|| deadline.); -} diff --git a/examples/core_reference/antipatterns.rs b/examples/core_reference/antipatterns.rs index 50fecc4f5..c031428bd 100644 --- a/examples/core_reference/antipatterns.rs +++ b/examples/core_reference/antipatterns.rs @@ -54,7 +54,7 @@ static AntipatternNoKeys: Component = |cx| { /// /// Only Component and Fragment nodes are susceptible to this issue. Dioxus mitigates this with components by providing /// an API for registering shared state without the ContextProvider pattern. -static AntipatternNestedFragments: Component<()> = |cx| { +static AntipatternNestedFragments: Component = |cx| { // Try to avoid heavily nesting fragments rsx!(cx, Fragment { @@ -82,7 +82,7 @@ static AntipatternNestedFragments: Component<()> = |cx| { /// However, calling set_state will *not* update the current version of state in the component. This should be easy to /// recognize from the function signature, but Dioxus will not update the "live" version of state. Calling `set_state` /// merely places a new value in the queue and schedules the component for a future update. -static AntipatternRelyingOnSetState: Component<()> = |cx| { +static AntipatternRelyingOnSetState: Component = |cx| { let (state, set_state) = use_state(&cx, || "Hello world").classic(); set_state("New state"); // This will return false! `state` will *still* be "Hello world" @@ -99,7 +99,7 @@ static AntipatternRelyingOnSetState: Component<()> = |cx| { /// - All components must start with an uppercase character /// /// i.e.: the following component will be rejected when attempted to be used in the rsx! macro -static antipattern_component: Component<()> = |cx, props| todo!(); +static antipattern_component: Component = |cx| todo!(); /// Antipattern: Misusing hooks /// --------------------------- @@ -153,7 +153,7 @@ static AntipatternMisusedHooks: Component = |cx| { /// } /// } /// }) -static _example: Component<()> = |cx, props| todo!(); +static _example: Component = |cx| todo!(); /// Antipattern: publishing components and hooks with all features enabled /// ---------------------------------------------------------------------- @@ -171,9 +171,9 @@ static _example: Component<()> = |cx, props| todo!(); /// /// This will only include the `core` dioxus crate which is relatively slim and fast to compile and avoids target-specific /// libraries. -static __example: Component<()> = |cx, props| todo!(); +static __example: Component = |cx| todo!(); -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { AntipatternNoKeys { data: std::collections::HashMap::new() } AntipatternNestedFragments {} diff --git a/examples/core_reference/basics.rs b/examples/core_reference/basics.rs index 11c3a59c3..3ba64e01a 100644 --- a/examples/core_reference/basics.rs +++ b/examples/core_reference/basics.rs @@ -9,7 +9,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { Greeting { diff --git a/examples/core_reference/children.rs b/examples/core_reference/children.rs index 48c940b60..8190f53d4 100644 --- a/examples/core_reference/children.rs +++ b/examples/core_reference/children.rs @@ -18,7 +18,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { Banner { @@ -31,7 +31,7 @@ pub static Example: Component<()> = |cx| { }) }; -pub static Banner: Component<()> = |cx| { +pub static Banner: Component = |cx| { cx.render(rsx! { div { h1 { "This is a great banner!" } diff --git a/examples/core_reference/conditional_rendering.rs b/examples/core_reference/conditional_rendering.rs index d73f562e0..9d15a735a 100644 --- a/examples/core_reference/conditional_rendering.rs +++ b/examples/core_reference/conditional_rendering.rs @@ -89,7 +89,7 @@ pub static Example2: Component = |cx| { }) }; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { let should_show = use_state(&cx, || false); let mut color_index = use_state(&cx, || 0); let color = match *color_index % 2 { diff --git a/examples/core_reference/controlled_inputs.rs b/examples/core_reference/controlled_inputs.rs index 2c97ec1ff..eccf46064 100644 --- a/examples/core_reference/controlled_inputs.rs +++ b/examples/core_reference/controlled_inputs.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() {} -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { @@ -10,7 +10,7 @@ pub static Example: Component<()> = |cx| { }; // A controlled component: -static ControlledSelect: Component<()> = |cx| { +static ControlledSelect: Component = |cx| { let value = use_state(&cx, || String::from("Grapefruit")); cx.render(rsx! { select { value: "{value}", onchange: move |evt| value.set(evt.value()), @@ -23,7 +23,7 @@ static ControlledSelect: Component<()> = |cx| { }; // TODO - how do uncontrolled things work? -static UncontrolledSelect: Component<()> = |cx| { +static UncontrolledSelect: Component = |cx| { let value = use_state(&cx, || String::new()); cx.render(rsx! { diff --git a/examples/core_reference/custom_elements.rs b/examples/core_reference/custom_elements.rs index 63024213a..0830ed01a 100644 --- a/examples/core_reference/custom_elements.rs +++ b/examples/core_reference/custom_elements.rs @@ -11,7 +11,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { custom_element { diff --git a/examples/core_reference/empty.rs b/examples/core_reference/empty.rs index aebf7e71f..78adce251 100644 --- a/examples/core_reference/empty.rs +++ b/examples/core_reference/empty.rs @@ -5,4 +5,4 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx, props| cx.render(rsx! { Fragment {} }); +pub static Example: Component = |cx| cx.render(rsx! { Fragment {} }); diff --git a/examples/core_reference/errorhandling.rs b/examples/core_reference/errorhandling.rs index cc21a62f9..3a2875bf6 100644 --- a/examples/core_reference/errorhandling.rs +++ b/examples/core_reference/errorhandling.rs @@ -23,14 +23,14 @@ fn main() {} /// This is one way to go about error handling (just toss things away with unwrap). /// However, if you get it wrong, the whole app will crash. /// This is pretty flimsy. -static App: Component<()> = |cx| { +static App: Component = |cx| { let data = get_data().unwrap(); cx.render(rsx!( div { "{data}" } )) }; /// This is a pretty verbose way of error handling /// However, it's still pretty good since we don't panic, just fail to render anything -static App1: Component<()> = |cx| { +static App1: Component = |cx| { let data = match get_data() { Some(data) => data, None => return None, @@ -46,7 +46,7 @@ static App1: Component<()> = |cx| { /// a user is logged in. /// /// Dioxus will throw an error in the console if the None-path is ever taken. -static App2: Component<()> = |cx| { +static App2: Component = |cx| { let data = get_data()?; cx.render(rsx!( div { "{data}" } )) }; @@ -54,14 +54,14 @@ static App2: Component<()> = |cx| { /// This is top-tier error handling since it displays a failure state. /// /// However, the error is lacking in context. -static App3: Component<()> = |cx, props| match get_data() { +static App3: Component = |cx| match get_data() { Some(data) => cx.render(rsx!( div { "{data}" } )), None => cx.render(rsx!( div { "Failed to load data :(" } )), }; /// For errors that return results, it's possible to short-circuit the match-based error handling with `.ok()` which converts /// a Result into an Option and lets you abort rendering by early-returning `None` -static App4: Component<()> = |cx| { +static App4: Component = |cx| { let data = get_data_err().ok()?; cx.render(rsx!( div { "{data}" } )) }; @@ -69,7 +69,7 @@ static App4: Component<()> = |cx| { /// This is great error handling since it displays a failure state... with context! /// /// Hopefully you'll never need to display a screen like this. It's rather bad taste -static App5: Component<()> = |cx, props| match get_data_err() { +static App5: Component = |cx| match get_data_err() { Ok(data) => cx.render(rsx!( div { "{data}" } )), Err(c) => cx.render(rsx!( div { "Failed to load data: {c}" } )), }; diff --git a/examples/core_reference/fragments.rs b/examples/core_reference/fragments.rs index 0532abd27..2a5b87373 100644 --- a/examples/core_reference/fragments.rs +++ b/examples/core_reference/fragments.rs @@ -11,7 +11,7 @@ use dioxus::prelude::*; // Returning multiple elements with rsx! or html! -static App1: Component<()> = |cx| { +static App1: Component = |cx| { cx.render(rsx! { h1 { } h2 { } @@ -20,7 +20,7 @@ static App1: Component<()> = |cx| { }; // Using the Fragment component -static App2: Component<()> = |cx| { +static App2: Component = |cx| { cx.render(rsx! { Fragment { div {} @@ -31,7 +31,7 @@ static App2: Component<()> = |cx| { }; // Using the `fragment` method on the NodeFactory -static App3: Component<()> = |cx| { +static App3: Component = |cx| { cx.render(LazyNodes::new(move |fac| { fac.fragment_from_iter([ fac.text(format_args!("A")), @@ -42,7 +42,7 @@ static App3: Component<()> = |cx| { })) }; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { App1 {} App2 {} diff --git a/examples/core_reference/global_css.rs b/examples/core_reference/global_css.rs index 6b7de70f0..a7b201d69 100644 --- a/examples/core_reference/global_css.rs +++ b/examples/core_reference/global_css.rs @@ -19,7 +19,7 @@ h1 {color: blue;} p {color: red;} "#; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { head { style { "{STYLE}" } } body { diff --git a/examples/core_reference/inline_styles.rs b/examples/core_reference/inline_styles.rs index c60364b75..d3459bcfd 100644 --- a/examples/core_reference/inline_styles.rs +++ b/examples/core_reference/inline_styles.rs @@ -10,7 +10,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { head { style: { background_color: "powderblue" } @@ -29,7 +29,7 @@ pub static Example: Component<()> = |cx| { // .... technically the rsx! macro is slightly broken at the moment and allows styles not wrapped in style {} // I haven't noticed any name collisions yet, and am tentatively leaving this behavior in.. // Don't rely on it. -static Example2: Component<()> = |cx| { +static Example2: Component = |cx| { cx.render(rsx! { div { color: "red" "hello world!" diff --git a/examples/core_reference/iterators.rs b/examples/core_reference/iterators.rs index 55d725a21..07452921c 100644 --- a/examples/core_reference/iterators.rs +++ b/examples/core_reference/iterators.rs @@ -12,7 +12,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { let example_data = use_state(&cx, || 0); let v = (0..10).map(|f| { diff --git a/examples/core_reference/listener.rs b/examples/core_reference/listener.rs index 891ee3743..b76e16046 100644 --- a/examples/core_reference/listener.rs +++ b/examples/core_reference/listener.rs @@ -7,7 +7,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { ButtonList {} NonUpdatingEvents {} @@ -16,7 +16,7 @@ pub static Example: Component<()> = |cx| { }; /// We can use `set_name` in multiple closures; the closures automatically *copy* the reference to set_name. -static ButtonList: Component<()> = |cx| { +static ButtonList: Component = |cx| { let name = use_state(&cx, || "...?"); let names = ["jack", "jill", "john", "jane"] @@ -33,7 +33,7 @@ static ButtonList: Component<()> = |cx| { /// This shows how listeners may be without a visible change in the display. /// Check the console. -static NonUpdatingEvents: Component<()> = |cx| { +static NonUpdatingEvents: Component = |cx| { rsx!(cx, div { button { onclick: move |_| log::info!("Did not cause any updates!") @@ -42,7 +42,7 @@ static NonUpdatingEvents: Component<()> = |cx| { }) }; -static DisablePropagation: Component<()> = |cx| { +static DisablePropagation: Component = |cx| { rsx!(cx, div { onclick: move |_| log::info!("event propagated to the div!") diff --git a/examples/core_reference/memo.rs b/examples/core_reference/memo.rs index 86831842b..061646a52 100644 --- a/examples/core_reference/memo.rs +++ b/examples/core_reference/memo.rs @@ -21,7 +21,7 @@ use dioxus::prelude::*; // By default, components with no props are always memoized. // A props of () is considered empty. -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { "100% memoized!" } }) @@ -61,9 +61,9 @@ pub struct MyProps3<'a> { name: &'a str, } // 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: Component<()>` pattern _will_ specify a lifetime, but that lifetime will be static which might +// Using the `pub static Example: Component` 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>, props: &'a MyProps3) -> DomTree<'a> { +fn Example3(cx: Scope<'a, MyProps3<'a>>) -> DomTree { cx.render(rsx! { div { "Not memoized! {cx.props.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>, props: &'a MyProps4) -> DomTree<'a> { +fn Example4<'a>(cx: Scope<'a, MyProps4<'a>>) -> DomTree { cx.render(rsx! { div { "Not memoized!", onclick: move |_| (props.onhandle)() } }) diff --git a/examples/core_reference/noderefs.rs b/examples/core_reference/noderefs.rs index c520abdca..a3d7053d4 100644 --- a/examples/core_reference/noderefs.rs +++ b/examples/core_reference/noderefs.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() {} -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { let p = 10; cx.render(rsx! { diff --git a/examples/core_reference/signals.rs b/examples/core_reference/signals.rs index 06fb6ab1b..d15e3f70a 100644 --- a/examples/core_reference/signals.rs +++ b/examples/core_reference/signals.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() {} -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { diff --git a/examples/core_reference/spreadpattern.rs b/examples/core_reference/spreadpattern.rs index c197f87e6..c24d008f2 100644 --- a/examples/core_reference/spreadpattern.rs +++ b/examples/core_reference/spreadpattern.rs @@ -9,7 +9,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { let props = MyProps { count: 0, live: true, diff --git a/examples/core_reference/statemanagement.rs b/examples/core_reference/statemanagement.rs index 06fb6ab1b..d15e3f70a 100644 --- a/examples/core_reference/statemanagement.rs +++ b/examples/core_reference/statemanagement.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() {} -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { diff --git a/examples/core_reference/suspense.rs b/examples/core_reference/suspense.rs index bbe536d3e..e624595fa 100644 --- a/examples/core_reference/suspense.rs +++ b/examples/core_reference/suspense.rs @@ -14,7 +14,7 @@ struct DogApi { } const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random"; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { let doggo = use_suspense( cx, || surf::get(ENDPOINT).recv_json::(), diff --git a/examples/core_reference/task.rs b/examples/core_reference/task.rs index 7fad94381..d213917c4 100644 --- a/examples/core_reference/task.rs +++ b/examples/core_reference/task.rs @@ -24,7 +24,7 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { let count = use_state(&cx, || 0); let mut direction = use_state(&cx, || 1); diff --git a/examples/core_reference/testing.rs b/examples/core_reference/testing.rs index ec10acaa3..aaef5fb7f 100644 --- a/examples/core_reference/testing.rs +++ b/examples/core_reference/testing.rs @@ -1,6 +1,6 @@ use dioxus::prelude::*; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { cx.render(rsx! { div { diff --git a/examples/core_reference/tostring.rs b/examples/core_reference/tostring.rs index 09f8d95d1..9c8563935 100644 --- a/examples/core_reference/tostring.rs +++ b/examples/core_reference/tostring.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; use dioxus::ssr; -pub static Example: Component<()> = |cx| { +pub static Example: Component = |cx| { let as_string = use_state(&cx, || { // Currently, SSR is only supported for whole VirtualDOMs // This is an easy/low hanging fruit to improve upon @@ -15,7 +15,7 @@ pub static Example: Component<()> = |cx| { }) }; -static SomeApp: Component<()> = |cx| { +static SomeApp: Component = |cx| { cx.render(rsx! { div { style: {background_color: "blue"} h1 {"Some amazing app or component"} diff --git a/examples/coroutine.rs b/examples/coroutine.rs index 0f647fde1..ee957bd34 100644 --- a/examples/coroutine.rs +++ b/examples/coroutine.rs @@ -27,7 +27,7 @@ fn main() { use dioxus::prelude::*; -static App: Component<()> = |cx| { +static App: Component = |cx| { let p1 = use_state(&cx, || 0); let p2 = use_state(&cx, || 0); diff --git a/examples/crm.rs b/examples/crm.rs index 2ae7d3ee0..a8eeb456b 100644 --- a/examples/crm.rs +++ b/examples/crm.rs @@ -19,7 +19,7 @@ pub struct Client { pub description: String, } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut clients = use_ref(&cx, || vec![] as Vec); let mut scene = use_state(&cx, || Scene::ClientsList); diff --git a/examples/desktop/crm.rs b/examples/desktop/crm.rs index f216f884f..5c3d50228 100644 --- a/examples/desktop/crm.rs +++ b/examples/desktop/crm.rs @@ -21,7 +21,7 @@ pub struct Client { pub description: String, } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut scene = use_state(&cx, || Scene::ClientsList); let clients = use_ref(&cx, || vec![] as Vec); diff --git a/examples/desktop/demo.rs b/examples/desktop/demo.rs index d327b7f32..1782d8cb0 100644 --- a/examples/desktop/demo.rs +++ b/examples/desktop/demo.rs @@ -8,7 +8,7 @@ fn main() { dioxus_desktop::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { cx.render(rsx!( div { "hello world!" diff --git a/examples/desktop/todomvc.rs b/examples/desktop/todomvc.rs index 2674d9dee..ff982a585 100644 --- a/examples/desktop/todomvc.rs +++ b/examples/desktop/todomvc.rs @@ -32,7 +32,7 @@ pub struct TodoItem { } pub type Todos = HashMap; -pub static App: Component<()> = |cx| { +pub static App: Component = |cx| { // Share our TodoList to the todos themselves use_provide_state(cx, Todos::new); @@ -140,7 +140,7 @@ pub fn TodoEntry((cx, props): Scope) -> Element { let todos = use_shared_state::(cx)?; let _todos = todos.read(); - let todo = _todos.get(&props.id)?; + let todo = _todos.get(&cx.props.id)?; let is_editing = use_state(&cx, || false); let completed = if todo.checked { "completed" } else { "" }; @@ -150,7 +150,7 @@ pub fn TodoEntry((cx, props): Scope) -> Element { div { class: "view" input { class: "toggle" r#type: "checkbox" id: "cbg-{todo.id}" checked: "{todo.checked}" onchange: move |evt| { - if let Some(todo) = todos.write().get_mut(&props.id) { + if let Some(todo) = todos.write().get_mut(&cx.props.id) { todo.checked = evt.value.parse().unwrap() } } @@ -163,7 +163,7 @@ pub fn TodoEntry((cx, props): Scope) -> Element { {is_editing.then(|| rsx!{ input { value: "{todo.contents}" oninput: move |evt| { - if let Some(todo) = todos.write().get_mut(&props.id) { + if let Some(todo) = todos.write().get_mut(&cx.props.id) { todo.contents = evt.value } }, diff --git a/examples/file_explorer.rs b/examples/file_explorer.rs index 025347b00..a2f168d6b 100644 --- a/examples/file_explorer.rs +++ b/examples/file_explorer.rs @@ -18,7 +18,7 @@ fn main() { }); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let file_manager = use_ref(&cx, Files::new); let files = file_manager.read(); diff --git a/examples/framework_benchmark.rs b/examples/framework_benchmark.rs index bf5b7da24..100169679 100644 --- a/examples/framework_benchmark.rs +++ b/examples/framework_benchmark.rs @@ -30,7 +30,7 @@ impl Label { } } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut items = use_ref(&cx, || vec![]); let mut selected = use_state(&cx, || None); @@ -140,24 +140,3 @@ static NOUNS: &[&str] = &[ "table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard", ]; - -// #[derive(PartialEq, Props)] -// struct RowProps<'a> { -// row_id: usize, -// label: &'a Label, -// } - -// fn Row(cx: Context, props: &RowProps) -> Element { -// rsx!(cx, tr { -// td { class:"col-md-1", "{cx.props.row_id}" } -// td { class:"col-md-1", onclick: move |_| { /* run onselect */ } -// a { class: "lbl", {cx.props.label.labels} } -// } -// td { class: "col-md-1" -// a { class: "remove", onclick: move |_| {/* remove */} -// span { class: "glyphicon glyphicon-remove remove" aria_hidden: "true" } -// } -// } -// td { class: "col-md-6" } -// }) -// } diff --git a/examples/hydration.rs b/examples/hydration.rs index a456c6468..3c4faa55d 100644 --- a/examples/hydration.rs +++ b/examples/hydration.rs @@ -19,7 +19,7 @@ fn main() { dioxus::desktop::launch_cfg(App, |c| c.with_prerendered(content)); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut val = use_state(&cx, || 0); cx.render(rsx! { diff --git a/examples/manual_edits.rs b/examples/manual_edits.rs index ace529ee6..5b0d0de4e 100644 --- a/examples/manual_edits.rs +++ b/examples/manual_edits.rs @@ -33,7 +33,7 @@ fn main() { AppendChildren { many: 1 }, ]; - let app: Component<()> = |cx| rsx!(cx, div { "some app" }); + let app: Component = |cx| rsx!(cx, div { "some app" }); dioxus_desktop::run(app, (), |c| c.with_edits(edits)); } diff --git a/examples/pattern_model.rs b/examples/pattern_model.rs index 7b827542e..252a000c9 100644 --- a/examples/pattern_model.rs +++ b/examples/pattern_model.rs @@ -33,7 +33,7 @@ fn main() { }); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let state = use_ref(&cx, || Calculator::new()); let clear_display = state.read().display_value.eq("0"); diff --git a/examples/pattern_reducer.rs b/examples/pattern_reducer.rs index 7441516a3..cd14460f6 100644 --- a/examples/pattern_reducer.rs +++ b/examples/pattern_reducer.rs @@ -11,7 +11,7 @@ fn main() { dioxus::desktop::launch(App); } -pub static App: Component<()> = |cx| { +pub static App: Component = |cx| { let state = use_state(&cx, PlayerState::new); let is_playing = state.is_playing(); diff --git a/examples/readme.rs b/examples/readme.rs index aa4cd9a8a..c3f0a3de7 100644 --- a/examples/readme.rs +++ b/examples/readme.rs @@ -7,7 +7,7 @@ fn main() { dioxus::desktop::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut count = use_state(&cx, || 0); cx.render(rsx! { diff --git a/examples/router.rs b/examples/router.rs index b3e6d60b5..47350ad16 100644 --- a/examples/router.rs +++ b/examples/router.rs @@ -23,7 +23,7 @@ pub enum Route { NotFound, } -static App: Component<()> = |cx| { +static App: Component = |cx| { let route = use_router(&cx, Route::parse); cx.render(rsx! { diff --git a/examples/rsx_usage.rs b/examples/rsx_usage.rs index a7205b8dd..195edac00 100644 --- a/examples/rsx_usage.rs +++ b/examples/rsx_usage.rs @@ -49,7 +49,7 @@ const NONE_ELEMENT: Option<()> = None; use baller::Baller; use dioxus::prelude::*; -pub static EXAMPLE: Component<()> = |cx| { +pub static EXAMPLE: Component = |cx| { let formatting = "formatting!"; let formatting_tuple = ("a", "b"); let lazy_fmt = format_args!("lazily formatted text"); diff --git a/examples/ssr.rs b/examples/ssr.rs index 55402f579..21a73b67b 100644 --- a/examples/ssr.rs +++ b/examples/ssr.rs @@ -7,7 +7,7 @@ fn main() { println!("{}", ssr::render_vdom(&vdom)); } -static APP: Component<()> = |cx| { +static APP: Component = |cx| { cx.render(rsx!( div { h1 { "Title" } diff --git a/examples/ssr/basic.rs b/examples/ssr/basic.rs index 89b976d42..916a9fa0e 100644 --- a/examples/ssr/basic.rs +++ b/examples/ssr/basic.rs @@ -12,7 +12,7 @@ fn main() { ) } -pub static App: Component<()> = |cx| { +pub static App: Component = |cx| { cx.render(rsx!( div { class: "overflow-hidden" diff --git a/examples/ssr/tofile.rs b/examples/ssr/tofile.rs index 8440074e8..9c64f14d5 100644 --- a/examples/ssr/tofile.rs +++ b/examples/ssr/tofile.rs @@ -24,7 +24,7 @@ fn main() { .unwrap(); } -pub static App: Component<()> = |cx| { +pub static App: Component = |cx| { cx.render(rsx!( div { class: "overflow-hidden" link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel:"stylesheet" } @@ -39,7 +39,7 @@ pub static App: Component<()> = |cx| { )) }; -pub static Header: Component<()> = |cx| { +pub static Header: Component = |cx| { cx.render(rsx! { div { header { class: "text-gray-400 bg-gray-900 body-font" @@ -65,7 +65,7 @@ pub static Header: Component<()> = |cx| { }) }; -pub static Hero: Component<()> = |cx| { +pub static Hero: Component = |cx| { // cx.render(rsx! { section{ class: "text-gray-400 bg-gray-900 body-font" @@ -103,7 +103,7 @@ pub static Hero: Component<()> = |cx| { } }) }; -pub static Entry: Component<()> = |cx| { +pub static Entry: Component = |cx| { // cx.render(rsx! { section{ class: "text-gray-400 bg-gray-900 body-font" @@ -116,7 +116,7 @@ pub static Entry: Component<()> = |cx| { }) }; -pub static StacksIcon: Component<()> = |cx| { +pub static StacksIcon: Component = |cx| { cx.render(rsx!( svg { xmlns: "http://www.w3.org/2000/svg" @@ -131,7 +131,7 @@ pub static StacksIcon: Component<()> = |cx| { } )) }; -pub static RightArrowIcon: Component<()> = |cx| { +pub static RightArrowIcon: Component = |cx| { cx.render(rsx!( svg { fill: "none" diff --git a/examples/tailwind.rs b/examples/tailwind.rs index 91365ead3..49da99ee8 100644 --- a/examples/tailwind.rs +++ b/examples/tailwind.rs @@ -14,7 +14,7 @@ fn main() { const STYLE: &str = "body {overflow:hidden;}"; -pub static App: Component<()> = |cx| { +pub static App: Component = |cx| { cx.render(rsx!( div { class: "overflow-hidden" style { "{STYLE}" } @@ -30,7 +30,7 @@ pub static App: Component<()> = |cx| { )) }; -pub static Header: Component<()> = |cx| { +pub static Header: Component = |cx| { cx.render(rsx! { div { header { class: "text-gray-400 bg-gray-900 body-font" @@ -56,7 +56,7 @@ pub static Header: Component<()> = |cx| { }) }; -pub static Hero: Component<()> = |cx| { +pub static Hero: Component = |cx| { // cx.render(rsx! { section{ class: "text-gray-400 bg-gray-900 body-font" @@ -94,7 +94,7 @@ pub static Hero: Component<()> = |cx| { } }) }; -pub static Entry: Component<()> = |cx| { +pub static Entry: Component = |cx| { // cx.render(rsx! { section{ class: "text-gray-400 bg-gray-900 body-font" @@ -107,7 +107,7 @@ pub static Entry: Component<()> = |cx| { }) }; -pub static StacksIcon: Component<()> = |cx| { +pub static StacksIcon: Component = |cx| { cx.render(rsx!( svg { // xmlns: "http://www.w3.org/2000/svg" @@ -122,7 +122,7 @@ pub static StacksIcon: Component<()> = |cx| { } )) }; -pub static RightArrowIcon: Component<()> = |cx| { +pub static RightArrowIcon: Component = |cx| { cx.render(rsx!( svg { fill: "none" diff --git a/examples/todomvc.rs b/examples/todomvc.rs index ca0df7c5b..a41f78d5e 100644 --- a/examples/todomvc.rs +++ b/examples/todomvc.rs @@ -22,7 +22,7 @@ pub struct TodoItem { } const STYLE: &str = include_str!("./assets/todomvc.css"); -const App: Component<()> = |cx| { +const App: Component = |cx| { let draft = use_state(&cx, || "".to_string()); let todos = use_state(&cx, || HashMap::>::new()); let filter = use_state(&cx, || FilterState::All); diff --git a/examples/weather_app.rs b/examples/weather_app.rs index 0ba2ffa0f..3317a1774 100644 --- a/examples/weather_app.rs +++ b/examples/weather_app.rs @@ -12,7 +12,7 @@ fn main() { const ENDPOINT: &str = "https://api.openweathermap.org/data/2.5/weather"; -static App: Component<()> = |cx| { +static App: Component = |cx| { // let body = use_suspense( cx, diff --git a/examples/web/async_web.rs b/examples/web/async_web.rs index a1a0f8bb1..e18b4269d 100644 --- a/examples/web/async_web.rs +++ b/examples/web/async_web.rs @@ -16,7 +16,7 @@ struct DogApi { message: String, } -static APP: Component<()> = |(cx, _props)| { +static APP: Component = |(cx, _props)| { let state = use_state(&cx, || 0); const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random/"; diff --git a/examples/web/basic.rs b/examples/web/basic.rs index ff70f8a1b..037402613 100644 --- a/examples/web/basic.rs +++ b/examples/web/basic.rs @@ -14,7 +14,7 @@ fn main() { dioxus_web::launch(APP) } -static APP: Component<()> = |cx| { +static APP: Component = |cx| { let mut count = use_state(&cx, || 3); let content = use_state(&cx, || String::from("h1")); let text_content = use_state(&cx, || String::from("Hello, world!")); @@ -68,13 +68,13 @@ static APP: Component<()> = |cx| { }) }; -fn render_bullets(cx: Context) -> Element { +fn render_bullets(cx: Scope) -> Element { rsx!(cx, div { "bite me" }) } -fn render_list(cx: Context, count: usize) -> Element { +fn render_list(cx: Scope, count: usize) -> Element { let items = (0..count).map(|f| { rsx! { li { "a - {f}" } @@ -86,4 +86,4 @@ fn render_list(cx: Context, count: usize) -> Element { rsx!(cx, ul { {items} }) } -static CHILD: Component<()> = |cx, _| rsx!(cx, div {"hello child"}); +static CHILD: Component = |cx, _| rsx!(cx, div {"hello child"}); diff --git a/examples/web/blah.rs b/examples/web/blah.rs index 5553ceede..95f3a5875 100644 --- a/examples/web/blah.rs +++ b/examples/web/blah.rs @@ -24,7 +24,7 @@ fn main() { dioxus_web::launch(App) } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut state = use_state(&cx, || 0); cx.render(rsx! { div { diff --git a/examples/web/btns.rs b/examples/web/btns.rs index a3c96ad7a..757627dbc 100644 --- a/examples/web/btns.rs +++ b/examples/web/btns.rs @@ -23,7 +23,7 @@ fn main() { // dioxus::web::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { dbg!("rednering parent"); cx.render(rsx! { div { @@ -40,7 +40,7 @@ static App: Component<()> = |cx| { }) }; -static But: Component<()> = |cx| { +static But: Component = |cx| { let mut count = use_state(&cx, || 0); // let d = Dropper { name: "asd" }; diff --git a/examples/web/crm2.rs b/examples/web/crm2.rs index 4f0eff48f..edbd534af 100644 --- a/examples/web/crm2.rs +++ b/examples/web/crm2.rs @@ -28,7 +28,7 @@ pub struct Client { pub description: String, } -static App: Component<()> = |cx| { +static App: Component = |cx| { let scene = use_state(&cx, || Scene::ClientsList); let clients = use_ref(&cx, || vec![] as Vec); diff --git a/examples/web/demo.rs b/examples/web/demo.rs index 6c21aa48d..d3f7e40e6 100644 --- a/examples/web/demo.rs +++ b/examples/web/demo.rs @@ -24,7 +24,7 @@ fn main() { dioxus_web::launch(App) } -pub static App: Component<()> = |cx| { +pub static App: Component = |cx| { cx.render(rsx!( div { class: "overflow-hidden" link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel:"stylesheet" } @@ -39,7 +39,7 @@ pub static App: Component<()> = |cx| { )) }; -pub static Header: Component<()> = |cx| { +pub static Header: Component = |cx| { cx.render(rsx! { div { header { class: "text-gray-400 bg-gray-900 body-font" @@ -65,7 +65,7 @@ pub static Header: Component<()> = |cx| { }) }; -pub static Hero: Component<()> = |cx| { +pub static Hero: Component = |cx| { // cx.render(rsx! { section{ class: "text-gray-400 bg-gray-900 body-font" @@ -103,7 +103,7 @@ pub static Hero: Component<()> = |cx| { } }) }; -pub static Entry: Component<()> = |cx| { +pub static Entry: Component = |cx| { // cx.render(rsx! { section{ class: "text-gray-400 bg-gray-900 body-font" @@ -116,7 +116,7 @@ pub static Entry: Component<()> = |cx| { }) }; -pub static StacksIcon: Component<()> = |cx| { +pub static StacksIcon: Component = |cx| { cx.render(rsx!( svg { // xmlns: "http://www.w3.org/2000/svg" @@ -131,7 +131,7 @@ pub static StacksIcon: Component<()> = |cx| { } )) }; -pub static RightArrowIcon: Component<()> = |cx| { +pub static RightArrowIcon: Component = |cx| { cx.render(rsx!( svg { fill: "none" diff --git a/examples/web_tick.rs b/examples/web_tick.rs index a9a297221..447bd1121 100644 --- a/examples/web_tick.rs +++ b/examples/web_tick.rs @@ -19,7 +19,7 @@ fn main() { dioxus::web::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut rng = SmallRng::from_entropy(); let rows = (0..1_000).map(|f| { let label = Label::new(&mut rng); diff --git a/examples/webview_web.rs b/examples/webview_web.rs index a31096be7..367094b2c 100644 --- a/examples/webview_web.rs +++ b/examples/webview_web.rs @@ -16,7 +16,7 @@ fn main() { dioxus::web::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut count = use_state(&cx, || 0); cx.render(rsx! { diff --git a/notes/Parity.md b/notes/Parity.md index fa51fff58..d4299dfd2 100644 --- a/notes/Parity.md +++ b/notes/Parity.md @@ -12,7 +12,7 @@ https://github.com/rustwasm/gloo For example, resize observer would function like this: ```rust -pub static Example: Component<()> = |cx, props|{ +pub static Example: Component = |cx| { let observer = use_resize_observer(); cx.render(rsx!( diff --git a/notes/SOLVEDPROBLEMS.md b/notes/SOLVEDPROBLEMS.md index baf88701b..c74b4117f 100644 --- a/notes/SOLVEDPROBLEMS.md +++ b/notes/SOLVEDPROBLEMS.md @@ -153,13 +153,13 @@ Notice that LiveComponent receivers (the client-side interpretation of a LiveCom The `VNodeTree` type is a very special type that allows VNodes to be created using a pluggable allocator. The html! macro creates something that looks like: ```rust -pub static Example: Component<()> = |cx, props|{ +pub static Example: Component = |cx| { html! {
"blah"
} }; // expands to... -pub static Example: Component<()> = |cx, props|{ +pub static Example: Component = |cx| { // This function converts a Fn(allocator) -> DomTree closure to a VNode struct that will later be evaluated. html_macro_to_vnodetree(move |allocator| { let mut node0 = allocator.alloc(VElement::div); @@ -216,7 +216,7 @@ struct ExampleContext { items: Vec } -fn Example<'src>(cx: Context<'src, ()>) -> DomTree<'src> { +fn Example<'src>(cx: Scope<'src, ()>) -> DomTree<'src> { let val: &'b ContextGuard = (&'b cx).use_context(|context: &'other ExampleContext| { // always select the last element context.items.last() @@ -313,7 +313,7 @@ Here's how react does it: Any "dirty" node causes an entire subtree render. Calling "setState" at the very top will cascade all the way down. This is particularly bad for this component design: ```rust -static APP: Component<()> = |cx, props|{ +static APP: Component = |cx| { let title = use_context(Title); cx.render(html!{
@@ -334,7 +334,7 @@ static APP: Component<()> = |cx, props|{
}) }; -static HEAVY_LIST: Component<()> = |cx, props|{ +static HEAVY_LIST: Component = |cx| { cx.render({ {0.100.map(i => )} }) @@ -348,7 +348,7 @@ An update to the use_context subscription will mark the node as dirty. The node The FC layout was altered to make life easier for us inside the VirtualDom. The "view" function returns an unbounded VNode object. Calling the "view" function is unsafe under the hood, but prevents lifetimes from leaking out of the function call. Plus, it's easier to write. Because there are no lifetimes on the output (occur purely under the hood), we can escape needing to annotate them. ```rust -fn component(cx: Context, props: &Props) -> DomTree { +fn component(cx: Scope) -> DomTree { } ``` @@ -378,7 +378,7 @@ struct Props { } -static Component: Component = |cx, props|{ +static Component: Component = |cx| { } ``` diff --git a/packages/core-macro/src/fc.rs b/packages/core-macro/src/fc.rs deleted file mode 100644 index 6d16bb8a8..000000000 --- a/packages/core-macro/src/fc.rs +++ /dev/null @@ -1,337 +0,0 @@ -use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; - -use syn::{ - parse::{Parse, ParseStream}, - Signature, -}; -use syn::{Attribute, Block, FnArg, Ident, Item, ItemFn, ReturnType, Type, Visibility}; - -/// A parsed version of the user's input -pub struct FunctionComponent { - // The actual contents of the function - block: Box, - - // // The user's props type - // props_type: Box, - arg: FnArg, - vis: Visibility, - attrs: Vec, - name: Ident, - return_type: Box, -} - -impl Parse for FunctionComponent { - fn parse(input: ParseStream) -> syn::Result { - let parsed: Item = input.parse()?; - - // Convert the parsed input into the Function block - let ItemFn { - attrs, - vis, - sig, - block, - } = ensure_fn_block(parsed)?; - - // Validate the user's signature - let sig = validate_signature(sig)?; - - // Validate the return type is actually something - let return_type = ensure_return_type(sig.output)?; - - // Get all the function args - let mut inputs = sig.inputs.into_iter(); - - // Collect the first arg - let first_arg: FnArg = inputs - .next() - .unwrap_or_else(|| syn::parse_quote! { _: &() }); - - // Extract the "context" object - // let props_type = validate_context_arg(&first_arg)?; - - /* - Extract the rest of the function arguments into a struct body - We require all inputs are strongly typed with names so we can destructure into the function body when expanded - - - */ - // let rest = inputs - // .map(|f| { - // // - // match f { - // FnArg::Typed(pat) => { - // match *pat.pat { - // syn::Pat::Type(asd) => {} - // _ => {} - // }; - // // - // } - // FnArg::Receiver(_) => {} - // } - // // let name = f - // let stream = f.into_token_stream(); - // (stream) - // }) - // .collect::>(); - - // Collect the rest of the args into a list of definitions to be used by the inline struct - - // Checking after param parsing may make it a little inefficient - // but that's a requirement for better error messages in case of receivers - // `>0` because first one is already consumed. - // if inputs.len() > 0 { - // let params: TokenStream = inputs.map(|it| it.to_token_stream()).collect(); - // return Err(syn::Error::new_spanned( - // params, - // "function components can accept at most one parameter for the props", - // )); - // } - let name = sig.ident; - - Ok(Self { - // props_type, - block, - arg: first_arg, - vis, - attrs, - name, - return_type, - }) - } -} -impl ToTokens for FunctionComponent { - fn to_tokens(&self, tokens: &mut TokenStream) { - // let FunctionComponentName { component_name } = name; - - let FunctionComponent { - block, - // props_type, - arg: _, - vis: _, - attrs: _, - name: function_name, - return_type: _, - } = self; - - // if function_name == component_name { - // return Err(syn::Error::new_spanned( - // component_name, - // "the component must not have the same name as the function", - // )); - // } - - let quoted = quote! { - - - #[doc(hidden)] - #[allow(non_camel_case_types)] - #[derive(PartialEq)] - pub struct #function_name<'a> { - // and some other attrs - ___p: std::marker::PhantomData<&'a ()> - } - - impl<'a> FC for #function_name<'a> { - fn render(cx: Context<'_>, props: &#function_name<'a>) -> VNode { - let #function_name { - .. - } = props; - - #block - } - } - - // mod __component_blah { - // use super::*; - - // #[derive(PartialEq)] - // pub struct Props<'a> { - // name: &'a str - // } - - // pub fn component<'a>(cx: &'a Context<'a, Props>) -> VNode<'a> { - // // Destructure the props into the parent scope - // // todo: handle expansion of lifetimes - // let Props { - // name - // } = cx.props; - - // #block - // } - // } - // #[allow(non_snake_case)] - // pub use __component_blah::component as #function_name; - }; - - quoted.to_tokens(tokens); - // let quoted = quote! { - // #[doc(hidden)] - // #[allow(non_camel_case_types)] - // #vis struct #function_name; - - // impl ::yew_functional::FunctionProvider for #function_name { - // type TProps = #props_type; - - // fn run(#arg) -> #ret_type { - // #block - // } - // } - - // #(#attrs)* - // #vis type #component_name = ::yew_functional::FunctionComponent<#function_name>; - // }; - } -} - -/// Ensure the user's input is actually a functional component -pub fn ensure_fn_block(item: Item) -> syn::Result { - match item { - Item::Fn(it) => Ok(it), - Item::Static(it) => { - let syn::ItemStatic { - attrs: _, - vis: _, - static_token: _, - mutability: _, - ident: _, - colon_token: _, - ty, - eq_token: _, - expr: _, - semi_token: _, - } = ⁢ - match ty.as_ref() { - Type::BareFn(_bare) => {} - // Type::Array(_) - // | Type::Group(_) - // | Type::ImplTrait(_) - // | Type::Infer(_) - // | Type::Macro(_) - // | Type::Never(_) - // | Type::Paren(_) - // | Type::Path(_) - // | Type::Ptr(_) - // | Type::Reference(_) - // | Type::Slice(_) - // | Type::TraitObject(_) - // | Type::Tuple(_) - // | Type::Verbatim(_) - _ => {} - }; - - // TODO: Add support for static block - // Ensure that the contents of the static block can be extracted to a function - // TODO: @Jon - // Decide if statics should be converted to functions (under the hood) or stay as statics - // They _do_ get promoted, but also have a &'static ref - Err(syn::Error::new_spanned( - it, - "`function_component` attribute not ready for statics", - )) - } - other => Err(syn::Error::new_spanned( - other, - "`function_component` attribute can only be applied to functions", - )), - } -} - -/// Ensure the user's function actually returns a VNode -pub fn ensure_return_type(output: ReturnType) -> syn::Result> { - match output { - ReturnType::Default => Err(syn::Error::new_spanned( - output, - "function components must return a `VNode`", - )), - ReturnType::Type(_, ty) => Ok(ty), - } -} - -/// Validate the users's input signature for the function component. -/// Returns an error if any of the conditions prove to be wrong; -pub fn validate_signature(sig: Signature) -> syn::Result { - if !sig.generics.params.is_empty() { - return Err(syn::Error::new_spanned( - sig.generics, - "function components can't contain generics", - )); - } - - if sig.asyncness.is_some() { - return Err(syn::Error::new_spanned( - sig.asyncness, - "function components can't be async", - )); - } - - if sig.constness.is_some() { - return Err(syn::Error::new_spanned( - sig.constness, - "const functions can't be function components", - )); - } - - if sig.abi.is_some() { - return Err(syn::Error::new_spanned( - sig.abi, - "extern functions can't be function components", - )); - } - - Ok(sig) -} - -// pub fn validate_context_arg(first_arg: &FnArg) -> syn::Result> { -// if let FnArg::Typed(arg) = first_arg { -// // if let Type::R -// // Input arg is a reference to an &mut Context -// // if let Type::Reference(ty) = &*arg.ty { -// // if ty.lifetime.is_some() { -// // return Err(syn::Error::new_spanned( -// // &ty.lifetime, -// // "reference must not have a lifetime", -// // )); -// // } - -// // if ty.mutability.is_some() { -// // return Err(syn::Error::new_spanned( -// // &ty.mutability, -// // "reference must not be mutable", -// // )); -// // } - -// // Ok(ty.elem.clone()) -// // } else { -// // let msg = format!( -// // "expected a reference to a `Context` object (try: `&mut {}`)", -// // arg.ty.to_token_stream() -// // ); -// // return Err(syn::Error::new_spanned(arg.ty.clone(), msg)); -// // } -// } else { -// return Err(syn::Error::new_spanned( -// first_arg, -// "function components can't accept a receiver", -// )); -// } -// } - -pub fn collect_inline_args() {} - -/// The named specified in the macro usage. -pub struct FunctionComponentName { - component_name: Ident, -} - -impl Parse for FunctionComponentName { - fn parse(input: ParseStream) -> syn::Result { - if input.is_empty() { - return Err(input.error("expected identifier for the component")); - } - - let component_name = input.parse()?; - - Ok(Self { component_name }) - } -} diff --git a/packages/core-macro/src/lib.rs b/packages/core-macro/src/lib.rs index cacdcdf3e..a196441b8 100644 --- a/packages/core-macro/src/lib.rs +++ b/packages/core-macro/src/lib.rs @@ -30,7 +30,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token /// /// ## Complete Reference Guide: /// ``` -/// const Example: Component<()> = |cx, props|{ +/// const Example: Component = |cx| { /// let formatting = "formatting!"; /// let formatting_tuple = ("a", "b"); /// let lazy_fmt = format_args!("lazily formatted text"); @@ -161,7 +161,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token /// pub struct BallerProps {} /// /// /// This component totally balls -/// pub fn Baller(cx: Context<()>) -> DomTree { +/// pub fn Baller(cx: Scope<()>) -> DomTree { /// todo!() /// } /// } @@ -172,7 +172,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token /// } /// /// /// This component is taller than most :) -/// pub fn Taller(cx: Context) -> DomTree { +/// pub fn Taller(cx: Scope) -> DomTree { /// let b = true; /// todo!() /// } diff --git a/packages/core-macro/src/rsxtemplate.rs b/packages/core-macro/src/rsxtemplate.rs index 1f712997d..9222d7117 100644 --- a/packages/core-macro/src/rsxtemplate.rs +++ b/packages/core-macro/src/rsxtemplate.rs @@ -72,7 +72,7 @@ impl ToTokens for RsxTemplate { // // create a lazy tree that accepts a bump allocator // let final_tokens = quote! { - // dioxus::prelude::LazyNodes::new(move |cx, props|{ + // dioxus::prelude::LazyNodes::new(move |cx| { // let bump = &cx.bump(); // #new_toks diff --git a/packages/core/benches/jsframework.rs b/packages/core/benches/jsframework.rs index 34884983a..30a37249d 100644 --- a/packages/core/benches/jsframework.rs +++ b/packages/core/benches/jsframework.rs @@ -23,7 +23,7 @@ criterion_group!(mbenches, create_rows); criterion_main!(mbenches); fn create_rows(c: &mut Criterion) { - static App: Component<()> = |cx| { + static App: Component = |cx| { let mut rng = SmallRng::from_entropy(); let rows = (0..10_000_usize).map(|f| { let label = Label::new(&mut rng); diff --git a/packages/core/examples/handler_thru_props.rs b/packages/core/examples/handler_thru_props.rs deleted file mode 100644 index cb22bb9d7..000000000 --- a/packages/core/examples/handler_thru_props.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![allow(non_snake_case)] - -use dioxus::prelude::*; -use dioxus_core as dioxus; -use dioxus_core_macro::*; -use dioxus_html as dioxus_elements; - -fn main() { - let _ = VirtualDom::new(App); -} - -fn App(cx: Scope<()>) -> Element { - // - cx.render(rsx!( - div { - Child {} - } - )) -} - -fn Child(cx: Scope<()>) -> Element { - // - cx.render(rsx!( - div { - h1 { - "Hello, World!" - } - } - )) -} diff --git a/packages/core/examples/handlerror.rs b/packages/core/examples/handlerror.rs deleted file mode 100644 index 0de55333e..000000000 --- a/packages/core/examples/handlerror.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! Handling errors and early aborts -//! -//! -//! -//! - -use dioxus_core::prelude::*; -use thiserror::Error; - -fn main() { - - /* - If a component returns None, do we leave it the same way it was before? - We spent all this time wiping the component - - */ -} diff --git a/packages/core/examples/hooks.rs b/packages/core/examples/hooks.rs deleted file mode 100644 index 131aae0e6..000000000 --- a/packages/core/examples/hooks.rs +++ /dev/null @@ -1,6 +0,0 @@ -use dioxus::prelude::*; -use dioxus_core as dioxus; -use dioxus_core_macro::*; -use dioxus_html as dioxus_elements; - -fn main() {} diff --git a/packages/core/examples/props_expand.rs b/packages/core/examples/props_expand.rs deleted file mode 100644 index 29d41129e..000000000 --- a/packages/core/examples/props_expand.rs +++ /dev/null @@ -1,9 +0,0 @@ -use dioxus_core as dioxus; -use dioxus_core_macro::*; - -fn main() {} - -#[derive(Props)] -struct ChildProps<'a> { - name: &'a str, -} diff --git a/packages/core/examples/rows.rs b/packages/core/examples/rows.rs deleted file mode 100644 index 2fdce90b8..000000000 --- a/packages/core/examples/rows.rs +++ /dev/null @@ -1,120 +0,0 @@ -#![allow(non_snake_case, non_upper_case_globals)] -//! This benchmark tests just the overhead of Dioxus itself. -//! -//! For the JS Framework Benchmark, both the framework and the browser is benchmarked together. Dioxus prepares changes -//! to be made, but the change application phase will be just as performant as the vanilla wasm_bindgen code. In essence, -//! we are measuring the overhead of Dioxus, not the performance of the "apply" phase. -//! -//! On my MBP 2019: -//! - Dioxus takes 3ms to create 1_000 rows -//! - Dioxus takes 30ms to create 10_000 rows -//! -//! As pure "overhead", these are amazing good numbers, mostly slowed down by hitting the global allocator. -//! These numbers don't represent Dioxus with the heuristic engine installed, so I assume it'll be even faster. - -use criterion::{criterion_group, criterion_main, Criterion}; -use dioxus_core as dioxus; -use dioxus_core::prelude::*; -use dioxus_core_macro::*; -use dioxus_html as dioxus_elements; -use rand::prelude::*; - -fn main() { - static App: Component<()> = |cx| { - let mut rng = SmallRng::from_entropy(); - let rows = (0..10_000_usize).map(|f| { - let label = Label::new(&mut rng); - rsx! { - Row { - row_id: f, - label: label - } - } - }); - cx.render(rsx! { - table { - tbody { - {rows} - } - } - }) - }; - - let mut dom = VirtualDom::new(App); - let g = dom.rebuild(); - assert!(g.edits.len() > 1); -} - -#[derive(PartialEq, Props)] -struct RowProps { - row_id: usize, - label: Label, -} -fn Row(cx: Scope) -> Element { - let [adj, col, noun] = cx.props.label.0; - cx.render(rsx! { - tr { - td { class:"col-md-1", "{cx.props.row_id}" } - td { class:"col-md-1", onclick: move |_| { /* run onselect */ } - a { class: "lbl", "{adj}" "{col}" "{noun}" } - } - td { class: "col-md-1" - a { class: "remove", onclick: move |_| {/* remove */} - span { class: "glyphicon glyphicon-remove remove" aria_hidden: "true" } - } - } - td { class: "col-md-6" } - } - }) -} - -#[derive(PartialEq)] -struct Label([&'static str; 3]); - -impl Label { - fn new(rng: &mut SmallRng) -> Self { - Label([ - ADJECTIVES.choose(rng).unwrap(), - COLOURS.choose(rng).unwrap(), - NOUNS.choose(rng).unwrap(), - ]) - } -} - -static ADJECTIVES: &[&str] = &[ - "pretty", - "large", - "big", - "small", - "tall", - "short", - "long", - "handsome", - "plain", - "quaint", - "clean", - "elegant", - "easy", - "angry", - "crazy", - "helpful", - "mushy", - "odd", - "unsightly", - "adorable", - "important", - "inexpensive", - "cheap", - "expensive", - "fancy", -]; - -static COLOURS: &[&str] = &[ - "red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", - "orange", -]; - -static NOUNS: &[&str] = &[ - "table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", - "pizza", "mouse", "keyboard", -]; diff --git a/packages/core/examples/works.rs b/packages/core/examples/works.rs index d8e171042..f521dcc42 100644 --- a/packages/core/examples/works.rs +++ b/packages/core/examples/works.rs @@ -52,12 +52,3 @@ fn great_grandchild<'a>(cx: Scope<'a, Grandchild>) -> Element<'a> { } }) } - -/* -can we implement memoization as a wrapper or something? Like we just intercept the -render function? - - - - -*/ diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index a7528b3ed..42e16d223 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -467,7 +467,7 @@ impl ScopeState { /// # Example /// /// ```rust, ignore - /// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} })); + /// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} })); /// dom.rebuild(); /// /// let base = dom.base_scope(); @@ -511,7 +511,7 @@ impl ScopeState { /// # Example /// /// ```rust, ignore - /// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} })); + /// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} })); /// dom.rebuild(); /// /// let base = dom.base_scope(); @@ -531,7 +531,7 @@ impl ScopeState { /// # Example /// /// ```rust, ignore - /// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} })); + /// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} })); /// dom.rebuild(); /// /// let base = dom.base_scope(); @@ -550,7 +550,7 @@ impl ScopeState { /// # Example /// /// ```rust, ignore - /// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} })); + /// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} })); /// dom.rebuild(); /// let base = dom.base_scope(); /// @@ -619,12 +619,12 @@ impl ScopeState { /// ```rust, ignore /// struct SharedState(&'static str); /// - /// static App: Component<()> = |cx, props|{ + /// static App: Component = |cx| { /// cx.use_hook(|_| cx.provide_context(SharedState("world")), |_| {}, |_| {}); /// rsx!(cx, Child {}) /// } /// - /// static Child: Component<()> = |cx| { + /// static Child: Component = |cx| { /// let state = cx.consume_state::(); /// rsx!(cx, div { "hello {state.0}" }) /// } diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 32e7c2534..09df37bb8 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -135,7 +135,7 @@ impl VirtualDom { /// ``` /// /// Note: the VirtualDom is not progressed, you must either "run_with_deadline" or use "rebuild" to progress it. - pub fn new(root: Component<()>) -> Self { + pub fn new(root: Component) -> Self { Self::new_with_props(root, ()) } @@ -468,7 +468,7 @@ impl VirtualDom { /// /// # Example /// ```rust, ignore - /// static App: Component<()> = |cx, props| cx.render(rsx!{ "hello world" }); + /// static App: Component = |cx| cx.render(rsx!{ "hello world" }); /// let mut dom = VirtualDom::new(); /// let edits = dom.rebuild(); /// @@ -505,7 +505,7 @@ impl VirtualDom { /// value: Shared<&'static str>, /// } /// - /// static App: Component = |cx, props|{ + /// static App: Component = |cx| { /// let val = cx.value.borrow(); /// cx.render(rsx! { div { "{val}" } }) /// }; diff --git a/packages/core/tests/earlyabort.rs b/packages/core/tests/earlyabort.rs index ef77beac9..9689aba5d 100644 --- a/packages/core/tests/earlyabort.rs +++ b/packages/core/tests/earlyabort.rs @@ -24,7 +24,7 @@ fn new_dom(app: Component

, props: P) -> VirtualDom { /// In debug, this should also toss a warning. #[test] fn test_early_abort() { - const app: Component<()> = |cx| { + const app: Component = |cx| { let val = cx.use_hook(|_| 0, |f| f); *val += 1; diff --git a/packages/core/tests/lifecycle.rs b/packages/core/tests/lifecycle.rs index dd8c66627..f87a403c7 100644 --- a/packages/core/tests/lifecycle.rs +++ b/packages/core/tests/lifecycle.rs @@ -45,7 +45,7 @@ fn manual_diffing() { #[test] fn events_generate() { - static App: Component<()> = |cx| { + static App: Component = |cx| { let count = cx.use_hook(|_| 0, |f| f); let inner = match *count { @@ -104,7 +104,7 @@ fn events_generate() { #[test] fn components_generate() { - static App: Component<()> = |cx| { + static App: Component = |cx| { let render_phase = cx.use_hook(|_| 0, |f| f); *render_phase += 1; @@ -121,7 +121,7 @@ fn components_generate() { }) }; - static Child: Component<()> = |cx| { + static Child: Component = |cx| { cx.render(rsx! { h1 {} }) @@ -220,7 +220,7 @@ fn components_generate() { #[test] fn component_swap() { - static App: Component<()> = |cx| { + static App: Component = |cx| { let render_phase = cx.use_hook(|_| 0, |f| f); *render_phase += 1; @@ -259,7 +259,7 @@ fn component_swap() { }) }; - static NavBar: Component<()> = |cx| { + static NavBar: Component = |cx| { println!("running navbar"); cx.render(rsx! { h1 { @@ -269,7 +269,7 @@ fn component_swap() { }) }; - static NavLink: Component<()> = |cx| { + static NavLink: Component = |cx| { println!("running navlink"); cx.render(rsx! { h1 { @@ -278,7 +278,7 @@ fn component_swap() { }) }; - static Dashboard: Component<()> = |cx| { + static Dashboard: Component = |cx| { println!("running dashboard"); cx.render(rsx! { div { @@ -287,7 +287,7 @@ fn component_swap() { }) }; - static Results: Component<()> = |cx| { + static Results: Component = |cx| { println!("running results"); cx.render(rsx! { div { diff --git a/packages/core/tests/sharedstate.rs b/packages/core/tests/sharedstate.rs index 51b93a0e5..3f04aa154 100644 --- a/packages/core/tests/sharedstate.rs +++ b/packages/core/tests/sharedstate.rs @@ -13,12 +13,12 @@ mod test_logging; fn shared_state_test() { struct MySharedState(&'static str); - static App: Component<()> = |cx| { + static App: Component = |cx| { cx.provide_context(MySharedState("world!")); cx.render(rsx!(Child {})) }; - static Child: Component<()> = |cx| { + static Child: Component = |cx| { let shared = cx.consume_context::()?; cx.render(rsx!("Hello, {shared.0}")) }; diff --git a/packages/core/tests/vdom_rebuild.rs b/packages/core/tests/vdom_rebuild.rs index b4da2418e..21619d9c2 100644 --- a/packages/core/tests/vdom_rebuild.rs +++ b/packages/core/tests/vdom_rebuild.rs @@ -19,7 +19,7 @@ use DomEdit::*; #[test] fn app_runs() { - static App: Component<()> = |cx| rsx!(cx, div{"hello"} ); + static App: Component = |cx| rsx!(cx, div{"hello"} ); let mut vdom = VirtualDom::new(App); let edits = vdom.rebuild(); @@ -27,7 +27,7 @@ fn app_runs() { #[test] fn fragments_work() { - static App: Component<()> = |cx| { + static App: Component = |cx| { cx.render(rsx!( div{"hello"} div{"goodbye"} @@ -41,7 +41,7 @@ fn fragments_work() { #[test] fn lists_work() { - static App: Component<()> = |cx| { + static App: Component = |cx| { cx.render(rsx!( h1 {"hello"} {(0..6).map(|f| rsx!(span{ "{f}" }))} @@ -54,7 +54,7 @@ fn lists_work() { #[test] fn conditional_rendering() { - static App: Component<()> = |cx| { + static App: Component = |cx| { cx.render(rsx!( h1 {"hello"} {true.then(|| rsx!(span{ "a" }))} @@ -87,13 +87,13 @@ fn conditional_rendering() { #[test] fn child_components() { - static App: Component<()> = |cx| { + static App: Component = |cx| { cx.render(rsx!( {true.then(|| rsx!(Child { }))} {false.then(|| rsx!(Child { }))} )) }; - static Child: Component<()> = |cx| { + static Child: Component = |cx| { cx.render(rsx!( h1 {"hello"} h1 {"goodbye"} diff --git a/packages/coroutines/Cargo.toml b/packages/coroutines/Cargo.toml deleted file mode 100644 index 3b6e47851..000000000 --- a/packages/coroutines/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "dioxus-coroutines" -version = "0.0.0" -edition = "2018" -repository = "https://github.com/DioxusLabs/dioxus/" -homepage = "https://dioxuslabs.com" -documentation = "https://dioxuslabs.com" -keywords = ["dom", "ui", "gui", "react", "wasm"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/packages/coroutines/src/lib.rs b/packages/coroutines/src/lib.rs deleted file mode 100644 index 1b4a90c93..000000000 --- a/packages/coroutines/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} diff --git a/packages/desktop/README.md b/packages/desktop/README.md index 18225ade7..cfee902ed 100644 --- a/packages/desktop/README.md +++ b/packages/desktop/README.md @@ -7,7 +7,7 @@ fn main() { dioxus::desktop::launch(App) } -static App: Component<()> = |cx| { +static App: Component = |cx| { let (count, set_count) = use_state(&cx, || 0); cx.render(rsx!( @@ -34,7 +34,7 @@ Window management, system trays, notifications, and other desktop-related functi Managing windows is done by simply rendering content into a `WebviewWindow` component. ```rust -static App: Component<()> = |cx| { +static App: Component = |cx| { rsx!(cx, WebviewWindow { "hello world" } ) } ``` @@ -46,7 +46,7 @@ Notifications also use a declarative approach. Sending a notification has never The api has been somewhat modeled after https://github.com/mikaelbr/node-notifier ```rust -static Notifications: Component<()> = |cx| { +static Notifications: Component = |cx| { cx.render(rsx!( Notification { title: "title" @@ -78,7 +78,7 @@ static Notifications: Component<()> = |cx| { Dioxus Desktop supports app trays, which can be built with native menu groups or with a custom window. ```rust -static Tray: Component<()> = |cx| { +static Tray: Component = |cx| { cx.render(rsx!( GlobalTray { MenuGroup { @@ -90,7 +90,7 @@ static Tray: Component<()> = |cx| { }; // using a builder -static Tray: Component<()> = |cx| { +static Tray: Component = |cx| { let menu = MenuGroup::builder(cx) .with_items([ MenuGroupItem::builder() @@ -107,7 +107,7 @@ static Tray: Component<()> = |cx| { } // or with a custom window -static Tray: Component<()> = |cx| { +static Tray: Component = |cx| { rsx!(cx, GlobalTray { div { "custom buttons here" } }) }; ``` @@ -116,7 +116,7 @@ static Tray: Component<()> = |cx| { Declaring menus is convenient and cross-platform. ```rust -static Menu: Component<()> = |cx| { +static Menu: Component = |cx| { cx.render(rsx!( MenuBarMajorItem { title: "File" MenuGroup { diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 9a0607218..c1eae3613 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -56,7 +56,7 @@ pub struct WebviewWindowProps<'a> { /// /// /// -pub fn WebviewWindow(cx: Context, props: &WebviewWindowProps) -> Element { +pub fn WebviewWindow(cx: Scope) -> Element { let dtcx = cx.consume_state::>()?; cx.use_hook( @@ -78,7 +78,7 @@ pub fn WebviewWindow(cx: Context, props: &WebviewWindowProps) -> Element { pub struct WindowHandle {} /// Get a handle to the current window from inside a component -pub fn use_current_window(cx: Context) -> Option { +pub fn use_current_window(cx: Scope) -> Option { todo!() } @@ -90,7 +90,7 @@ fn syntax_works() { use dioxus_hooks::*; use dioxus_html as dioxus_elements; - static App: Component<()> = |cx| { + static App: Component = |cx| { cx.render(rsx! { // left window WebviewWindow { diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index 246360fad..523c6fa0d 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -28,11 +28,11 @@ use wry::{ webview::{WebView, WebViewBuilder}, }; -pub fn launch(root: Component<()>) { +pub fn launch(root: Component) { launch_with_props(root, (), |c| c) } pub fn launch_cfg( - root: Component<()>, + root: Component, config_builder: impl for<'a, 'b> FnOnce(&'b mut DesktopConfig<'a>) -> &'b mut DesktopConfig<'a>, ) { launch_with_props(root, (), config_builder) diff --git a/packages/hooks/src/usecollection.rs b/packages/hooks/src/usecollection.rs index 47005e57b..0eed35b31 100644 --- a/packages/hooks/src/usecollection.rs +++ b/packages/hooks/src/usecollection.rs @@ -36,7 +36,7 @@ uses the same memoization on top of the use_context API. Here's a fully-functional todo app using the use_map API: ```rust -static TodoList: Component<()> = |cx, props|{ +static TodoList: Component = |cx| { let todos = use_map(cx, || HashMap::new()); let input = use_ref(|| None); diff --git a/packages/hooks/src/usestate.rs b/packages/hooks/src/usestate.rs index 03bcf9c4c..88caea82d 100644 --- a/packages/hooks/src/usestate.rs +++ b/packages/hooks/src/usestate.rs @@ -46,7 +46,7 @@ impl<'a, P, T> UseStateA<'a, T> for Scope<'a, P> { /// Usage: /// /// ```ignore -/// const Example: Component<()> = |cx| { +/// const Example: Component = |cx| { /// let counter = use_state(&cx, || 0); /// /// cx.render(rsx! { diff --git a/packages/html/src/elements.rs b/packages/html/src/elements.rs index db4b3442c..cd8656ccc 100644 --- a/packages/html/src/elements.rs +++ b/packages/html/src/elements.rs @@ -1165,4 +1165,11 @@ builder_constructors! { }; + /// Build a + /// [``](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g) + /// element. + g <> "http://www.w3.org/2000/svg" { + + }; + } diff --git a/packages/liveview/README.md b/packages/liveview/README.md index 4a05d9f10..5bbd8b75a 100644 --- a/packages/liveview/README.md +++ b/packages/liveview/README.md @@ -39,7 +39,7 @@ async fn order_shoes(mut req: WebsocketRequest) -> Response { dioxus::liveview::launch(App, stream).await; } -fn App(cx: Context, props: &()) -> Element { +fn App(cx: Scope<()>) -> Element { let mut count = use_state(&cx, || 0); cx.render(rsx!( button { onclick: move |_| count += 1, "Incr" } diff --git a/packages/mobile/src/lib.rs b/packages/mobile/src/lib.rs index e11765dda..938d4e957 100644 --- a/packages/mobile/src/lib.rs +++ b/packages/mobile/src/lib.rs @@ -26,10 +26,7 @@ fn init_logging() { static HTML_CONTENT: &'static str = include_str!("../../desktop/src/index.html"); -pub fn launch( - root: Component<()>, - builder: fn(WindowBuilder) -> WindowBuilder, -) -> anyhow::Result<()> { +pub fn launch(root: Component, builder: fn(WindowBuilder) -> WindowBuilder) -> anyhow::Result<()> { launch_with_props(root, (), builder) } pub fn launch_with_props( diff --git a/packages/router/Cargo.toml b/packages/router/Cargo.toml index 41822b97f..0588a2038 100644 --- a/packages/router/Cargo.toml +++ b/packages/router/Cargo.toml @@ -15,9 +15,8 @@ dioxus-core = { path = "../core", version = "^0.1.3", default-features = false } dioxus-html = { path = "../html", version = "^0.1.0", default-features = false } dioxus-core-macro = { path = "../core-macro", version = "^0.1.2" } -serde = "1.0.130" +serde = "1" url = "2.2.2" -url_serde = "0.2.0" serde_urlencoded = "0.7" web-sys = { version = "0.3", features = [ @@ -33,7 +32,7 @@ web-sys = { version = "0.3", features = [ ], optional = true } wasm-bindgen = { version = "0.2", optional = true } js-sys = { version = "0.3", optional = true } -gloo = { version = "0.4", optional = true } +gloo = { version = "0.5", optional = true } [features] diff --git a/packages/router/README.md b/packages/router/README.md index 05181ec9b..4cfa98c9d 100644 --- a/packages/router/README.md +++ b/packages/router/README.md @@ -16,7 +16,7 @@ enum AppRoute { NotFound } -static App: Component<()> = |cx| { +static App: Component = |cx| { let route = use_router(cx, AppRoute::parse); match route { @@ -30,7 +30,7 @@ static App: Component<()> = |cx| { Adding links into your app: ```rust -static Leaf: Component<()> = |cx| { +static Leaf: Component = |cx| { rsx!(cx, div { Link { to: AppRoute::Home } }) diff --git a/packages/router/examples/simple.rs b/packages/router/examples/simple.rs index eb5e7477f..134237dbb 100644 --- a/packages/router/examples/simple.rs +++ b/packages/router/examples/simple.rs @@ -10,7 +10,7 @@ fn main() { dioxus_web::launch(APP); } -static APP: Component<()> = |cx| { +static APP: Component = |cx| { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] enum Route { Home, diff --git a/packages/ssr/README.md b/packages/ssr/README.md index 02f6e09d8..59bf28baa 100644 --- a/packages/ssr/README.md +++ b/packages/ssr/README.md @@ -5,7 +5,7 @@ Render a Dioxus VirtualDOM to a string. ```rust // Our app: -const App: Component<()> = |cx, props| rsx!(cx, div {"hello world!"}); +const App: Component = |cx| rsx!(cx, div {"hello world!"}); // Build the virtualdom from our app let mut vdom = VirtualDOM::new(App); diff --git a/packages/ssr/src/lib.rs b/packages/ssr/src/lib.rs index 075ef0908..23e93084f 100644 --- a/packages/ssr/src/lib.rs +++ b/packages/ssr/src/lib.rs @@ -31,7 +31,7 @@ impl SsrRenderer { } } - pub fn render_lazy<'a>(&'a mut self, f: Option>) -> String { + pub fn render_lazy<'a>(&'a mut self, f: LazyNodes<'a, '_>) -> String { let bump = &mut self.inner as *mut _; let s = self.render_inner(f); // reuse the bump's memory @@ -39,7 +39,7 @@ impl SsrRenderer { s } - fn render_inner<'a>(&'a self, f: Option>) -> String { + fn render_inner<'a>(&'a self, f: LazyNodes<'a, '_>) -> String { let factory = NodeFactory::new(&self.inner); let root = f.into_vnode(factory); format!( @@ -53,7 +53,7 @@ impl SsrRenderer { } } -pub fn render_lazy<'a>(f: Option>) -> String { +pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String { let bump = bumpalo::Bump::new(); let borrowed = ≎ @@ -113,7 +113,7 @@ pub fn render_vdom_scope(vdom: &VirtualDom, scope: ScopeId) -> Option { /// /// ## Example /// ```ignore -/// static App: Component<()> = |cx, props|cx.render(rsx!(div { "hello world" })); +/// static App: Component = |cx| cx.render(rsx!(div { "hello world" })); /// let mut vdom = VirtualDom::new(App); /// vdom.rebuild(); /// @@ -301,13 +301,13 @@ mod tests { use dioxus_core_macro::*; use dioxus_html as dioxus_elements; - static SIMPLE_APP: Component<()> = |cx| { + static SIMPLE_APP: Component = |cx| { cx.render(rsx!(div { "hello world!" })) }; - static SLIGHTLY_MORE_COMPLEX: Component<()> = |cx| { + static SLIGHTLY_MORE_COMPLEX: Component = |cx| { cx.render(rsx! { div { title: "About W3Schools" @@ -326,14 +326,14 @@ mod tests { }) }; - static NESTED_APP: Component<()> = |cx| { + static NESTED_APP: Component = |cx| { cx.render(rsx!( div { SIMPLE_APP {} } )) }; - static FRAGMENT_APP: Component<()> = |cx| { + static FRAGMENT_APP: Component = |cx| { cx.render(rsx!( div { "f1" } div { "f2" } @@ -389,7 +389,7 @@ mod tests { #[test] fn styles() { - static STLYE_APP: Component<()> = |cx| { + static STLYE_APP: Component = |cx| { cx.render(rsx! { div { color: "blue", font_size: "46px" } }) diff --git a/packages/web/examples/async.rs b/packages/web/examples/async.rs index 91a5ac33c..c045ca5e4 100644 --- a/packages/web/examples/async.rs +++ b/packages/web/examples/async.rs @@ -14,7 +14,7 @@ fn main() { dioxus_web::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut count = use_state(&cx, || 0); cx.push_future(|| async move { diff --git a/packages/web/examples/js_bench.rs b/packages/web/examples/js_bench.rs index 0295ef983..d9ddc7e1c 100644 --- a/packages/web/examples/js_bench.rs +++ b/packages/web/examples/js_bench.rs @@ -106,7 +106,7 @@ impl Label { } } -static App: Component<()> = |cx| { +static App: Component = |cx| { let mut items = use_ref(&cx, || vec![]); let mut selected = use_state(&cx, || None); @@ -219,24 +219,3 @@ static NOUNS: &[&str] = &[ "table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard", ]; - -// #[derive(PartialEq, Props)] -// struct RowProps<'a> { -// row_id: usize, -// label: &'a Label, -// } - -// fn Row(cx: Context, props: &RowProps) -> Element { -// rsx!(cx, tr { -// td { class:"col-md-1", "{cx.props.row_id}" } -// td { class:"col-md-1", onclick: move |_| { /* run onselect */ } -// a { class: "lbl", {cx.props.label.labels} } -// } -// td { class: "col-md-1" -// a { class: "remove", onclick: move |_| {/* remove */} -// span { class: "glyphicon glyphicon-remove remove" aria_hidden: "true" } -// } -// } -// td { class: "col-md-6" } -// }) -// } diff --git a/packages/web/examples/simple.rs b/packages/web/examples/simple.rs index ffb572314..d3f2f078b 100644 --- a/packages/web/examples/simple.rs +++ b/packages/web/examples/simple.rs @@ -13,7 +13,7 @@ fn main() { dioxus_web::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { let show = use_state(&cx, || true); let inner = match *show { diff --git a/packages/web/examples/suspense.rs b/packages/web/examples/suspense.rs index 84c3b5f83..30a15a123 100644 --- a/packages/web/examples/suspense.rs +++ b/packages/web/examples/suspense.rs @@ -14,7 +14,7 @@ fn main() { dioxus_web::launch(App); } -static App: Component<()> = |cx| { +static App: Component = |cx| { todo!("suspense is broken") // let doggo = suspend(|| async move { // #[derive(serde::Deserialize)] diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index 73c9465b6..251597d49 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -84,11 +84,11 @@ mod ric_raf; /// dioxus_web::launch(App); /// } /// -/// static App: Component<()> = |cx| { +/// static App: Component = |cx| { /// rsx!(cx, div {"hello world"}) /// } /// ``` -pub fn launch(root_component: Component<()>) { +pub fn launch(root_component: Component) { launch_with_props(root_component, (), |c| c); }