depreciate the render macro

This commit is contained in:
Evan Almloff committed 2024-01-16 13:18:46 -06:00
1 parent 90d0164b9e
commit e65c5f0eb3
148 files changed
+459 -458

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! ( rsx! (
div { style: "text-align: center;", div { style: "text-align: center;",
h1 { "🌗 Dioxus 🚀" } h1 { "🌗 Dioxus 🚀" }
h3 { "Frontend that scales." } h3 { "Frontend that scales." }
+1 -1
View File
@@ -5,7 +5,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
align_content: "a", align_content: "a",
align_items: "a", align_items: "a",
+1 -1
View File
@@ -52,7 +52,7 @@ fn app() -> Element {
events.push_back(event); events.push_back(event);
}; };
render! { rsx! {
div { style: "{CONTAINER_STYLE}", div { style: "{CONTAINER_STYLE}",
div { div {
style: "{RECT_STYLE}", style: "{RECT_STYLE}",
+1 -1
View File
@@ -57,7 +57,7 @@ fn app() -> Element {
_ => {} _ => {}
}; };
render! { rsx! {
style { {include_str!("./assets/calculator.css")} } style { {include_str!("./assets/calculator.css")} }
div { id: "wrapper", div { id: "wrapper",
div { class: "app", div { class: "app",
+1 -1
View File
@@ -16,7 +16,7 @@ fn app() -> Element {
} }
}); });
render! { rsx! {
div { "High-Five counter: {count}" } div { "High-Five counter: {count}" }
} }
} }
+2 -2
View File
@@ -27,7 +27,7 @@ fn app() -> Element {
); );
}; };
render! { rsx! {
h1 { "This is your email" } h1 { "This is your email" }
button { onclick: open_compose_window, "Click to compose a new email" } button { onclick: open_compose_window, "Click to compose a new email" }
ul { ul {
@@ -44,7 +44,7 @@ fn app() -> Element {
fn compose(send: Rc<dyn Fn(String)>) -> Element { fn compose(send: Rc<dyn Fn(String)>) -> Element {
let mut user_input = use_signal(String::new); let mut user_input = use_signal(String::new);
render! { rsx! {
div { div {
h1 { "Compose a new email" } h1 { "Compose a new email" }
+1 -1
View File
@@ -25,7 +25,7 @@ fn app() -> Element {
} }
}); });
render! { rsx! {
div { div {
h1 { "Input Roulette" } h1 { "Input Roulette" }
for i in 0..100 { for i in 0..100 {
+1 -1
View File
@@ -11,7 +11,7 @@ fn app() -> Element {
let mut counters = use_signal(|| vec![0, 0, 0]); let mut counters = use_signal(|| vec![0, 0, 0]);
let mut sum = use_selector(move || counters.read().iter().copied().sum::<usize>()); let mut sum = use_selector(move || counters.read().iter().copied().sum::<usize>());
render! { rsx! {
div { div {
button { onclick: move |_| counters.write().push(0), "Add counter" } button { onclick: move |_| counters.write().push(0), "Add counter" }
button { onclick: move |_| { counters.write().pop(); }, "Remove counter" } button { onclick: move |_| { counters.write().pop(); }, "Remove counter" }
+4 -4
View File
@@ -14,7 +14,7 @@ type Clients = Signal<Vec<Client>>;
fn app() -> Element { fn app() -> Element {
use_context_provider::<Clients>(|| Signal::new(vec![])); use_context_provider::<Clients>(|| Signal::new(vec![]));
render! { rsx! {
link { link {
rel: "stylesheet", rel: "stylesheet",
href: "https://unpkg.com/purecss@2.0.6/build/pure-min.css", href: "https://unpkg.com/purecss@2.0.6/build/pure-min.css",
@@ -60,7 +60,7 @@ pub struct Client {
fn ClientList() -> Element { fn ClientList() -> Element {
let mut clients = use_context::<Clients>(); let mut clients = use_context::<Clients>();
render! { rsx! {
h2 { "List of Clients" } h2 { "List of Clients" }
Link { to: Route::ClientAdd {}, class: "pure-button pure-button-primary", "Add Client" } Link { to: Route::ClientAdd {}, class: "pure-button pure-button-primary", "Add Client" }
Link { to: Route::Settings {}, class: "pure-button", "Settings" } Link { to: Route::Settings {}, class: "pure-button", "Settings" }
@@ -88,7 +88,7 @@ fn ClientAdd() -> Element {
dioxus_router::router().push(Route::ClientList {}); dioxus_router::router().push(Route::ClientList {});
}; };
render! { rsx! {
h2 { "Add new Client" } h2 { "Add new Client" }
form { class: "pure-form pure-form-aligned", onsubmit: submit_client, form { class: "pure-form pure-form-aligned", onsubmit: submit_client,
@@ -138,7 +138,7 @@ fn ClientAdd() -> Element {
#[component] #[component]
fn Settings() -> Element { fn Settings() -> Element {
render! { rsx! {
h2 { "Settings" } h2 { "Settings" }
button { button {
+1 -1
View File
@@ -5,7 +5,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
p { p {
"This should show an image:" "This should show an image:"
+1 -1
View File
@@ -30,7 +30,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { h1 { "hello world!" } } div { h1 { "hello world!" } }
} }
} }
+1 -1
View File
@@ -7,7 +7,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut disabled = use_signal(|| false); let mut disabled = use_signal(|| false);
render! { rsx! {
div { div {
button { onclick: move |_| disabled.toggle(), button { onclick: move |_| disabled.toggle(),
"click to " "click to "
+6 -6
View File
@@ -15,10 +15,10 @@ fn app() -> Element {
.await; .await;
let Ok(breeds) = list else { let Ok(breeds) = list else {
return render! { "error fetching breeds" }; return rsx! { "error fetching breeds" };
}; };
render! { rsx! {
for cur_breed in breeds.message.keys().take(10).cloned() { for cur_breed in breeds.message.keys().take(10).cloned() {
li { key: "{cur_breed}", li { key: "{cur_breed}",
button { onclick: move |_| breed.set(cur_breed.clone()), button { onclick: move |_| breed.set(cur_breed.clone()),
@@ -30,10 +30,10 @@ fn app() -> Element {
}); });
let Some(breed_list) = breed_list.value().cloned() else { let Some(breed_list) = breed_list.value().cloned() else {
return render! { "loading breeds..." }; return rsx! { "loading breeds..." };
}; };
render! { rsx! {
h1 { "Select a dog breed!" } h1 { "Select a dog breed!" }
div { height: "500px", display: "flex", div { height: "500px", display: "flex",
ul { flex: "50%", {breed_list} } ul { flex: "50%", {breed_list} }
@@ -53,13 +53,13 @@ fn BreedPic(breed: Signal<String>) -> Element {
}); });
match fut.value().read().as_ref() { match fut.value().read().as_ref() {
Some(Ok(resp)) => render! { Some(Ok(resp)) => rsx! {
div { div {
button { onclick: move |_| fut.restart(), "Click to fetch another doggo" } button { onclick: move |_| fut.restart(), "Click to fetch another doggo" }
img { max_width: "500px", max_height: "500px", src: "{resp.message}" } img { max_width: "500px", max_height: "500px", src: "{resp.message}" }
} }
}, },
_ => render! { "loading image..." }, _ => rsx! { "loading image..." },
} }
} }
+1 -1
View File
@@ -17,7 +17,7 @@ fn app() -> Element {
response.respond(Response::new(include_bytes!("./assets/logo.png").to_vec())); response.respond(Response::new(include_bytes!("./assets/logo.png").to_vec()));
}); });
render! { rsx! {
div { div {
img { src: "/logos/logo.png" } img { src: "/logos/logo.png" }
} }
+3 -3
View File
@@ -5,9 +5,9 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
ErrorBoundary { ErrorBoundary {
handle_error: |error: CapturedError| render! {"Found error {error}"}, handle_error: |error: CapturedError| rsx! {"Found error {error}"},
DemoC { x: 1 } DemoC { x: 1 }
} }
} }
@@ -19,7 +19,7 @@ fn DemoC(x: i32) -> Element {
result.throw()?; result.throw()?;
render! { rsx! {
h1 { "{x}" } h1 { "{x}" }
} }
} }
+2 -2
View File
@@ -23,7 +23,7 @@ fn app() -> Element {
}); });
match future.value().read().as_ref() { match future.value().read().as_ref() {
Some(v) => render!( p { "{v}" } ), Some(v) => rsx!( p { "{v}" } ),
_ => render!( p { "waiting.." } ), _ => rsx!( p { "waiting.." } ),
} }
} }
+2 -2
View File
@@ -22,7 +22,7 @@ const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css"));
fn app() -> Element { fn app() -> Element {
let mut files = use_signal(Files::new); let mut files = use_signal(Files::new);
render! { rsx! {
div { div {
link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet" } link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet" }
header { header {
@@ -34,7 +34,7 @@ fn app() -> Element {
main { main {
{files.read().path_names.iter().enumerate().map(|(dir_id, path)| { {files.read().path_names.iter().enumerate().map(|(dir_id, path)| {
let path_end = path.split('/').last().unwrap_or(path.as_str()); let path_end = path.split('/').last().unwrap_or(path.as_str());
render! ( rsx! (
div { div {
class: "folder", class: "folder",
key: "{path}", key: "{path}",
+1 -1
View File
@@ -30,7 +30,7 @@ fn App() -> Element {
} }
}; };
render! { rsx! {
label { label {
input { input {
r#type: "checkbox", r#type: "checkbox",
+1 -1
View File
@@ -11,7 +11,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render!( rsx!(
div { h1 { "drag a file here and check your console" } } div { h1 { "drag a file here and check your console" } }
) )
} }
+5 -5
View File
@@ -32,7 +32,7 @@ enum Route {
#[component] #[component]
fn Footer() -> Element { fn Footer() -> Element {
render! { rsx! {
div { div {
Outlet::<Route> {} Outlet::<Route> {}
@@ -60,20 +60,20 @@ fn Footer() -> Element {
#[component] #[component]
fn Home() -> Element { fn Home() -> Element {
render!("Home") rsx!("Home")
} }
#[component] #[component]
fn Games() -> Element { fn Games() -> Element {
render!("Games") rsx!("Games")
} }
#[component] #[component]
fn Play() -> Element { fn Play() -> Element {
render!("Play") rsx!("Play")
} }
#[component] #[component]
fn Settings() -> Element { fn Settings() -> Element {
render!("Settings") rsx!("Settings")
} }
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
h1 { "Form" } h1 { "Form" }
form { form {
+2 -2
View File
@@ -7,7 +7,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
generic_child { data: 0 } generic_child { data: 0 }
} }
} }
@@ -18,7 +18,7 @@ struct GenericChildProps<T: Display + PartialEq + Clone + 'static> {
} }
fn generic_child<T: Display + PartialEq + Clone>(props: GenericChildProps<T>) -> Element { fn generic_child<T: Display + PartialEq + Clone>(props: GenericChildProps<T>) -> Element {
render! { rsx! {
div { "{props.data}" } div { "{props.data}" }
} }
} }
+1 -1
View File
@@ -5,7 +5,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { "Hello, world!" } div { "Hello, world!" }
} }
} }
+1 -1
View File
@@ -27,7 +27,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut val = use_signal(|| 0); let mut val = use_signal(|| 0);
render! { rsx! {
div { div {
h1 { "hello world. Count: {val}" } h1 { "hello world. Count: {val}" }
button { onclick: move |_| val += 1, "click to increment" } button { onclick: move |_| val += 1, "click to increment" }
+2 -2
View File
@@ -35,7 +35,7 @@ const FIELDS: &[(&str, &str)] = &[
]; ];
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { margin_left: "30px", div { margin_left: "30px",
{select_example()}, {select_example()},
div { div {
@@ -137,7 +137,7 @@ fn app() -> Element {
} }
fn select_example() -> Element { fn select_example() -> Element {
render! { rsx! {
div { div {
select { select {
id: "selection", id: "selection",
+4 -4
View File
@@ -7,7 +7,7 @@ fn main() {
#[component] #[component]
fn App() -> Element { fn App() -> Element {
render! ( rsx! (
div { div {
p { a { href: "http://dioxuslabs.com/", "Default link - links outside of your app" } } p { a { href: "http://dioxuslabs.com/", "Default link - links outside of your app" } }
p { p {
@@ -35,7 +35,7 @@ enum Route {
#[component] #[component]
fn Header() -> Element { fn Header() -> Element {
render! { rsx! {
h1 { "Your app here" } h1 { "Your app here" }
ul { ul {
li { li {
@@ -51,10 +51,10 @@ fn Header() -> Element {
#[component] #[component]
fn Home() -> Element { fn Home() -> Element {
render!( h1 { "Home" } ) rsx!( h1 { "Home" } )
} }
#[component] #[component]
fn Settings() -> Element { fn Settings() -> Element {
render!( h1 { "Settings" } ) rsx!( h1 { "Settings" } )
} }
+1 -1
View File
@@ -29,7 +29,7 @@ fn app() -> Element {
} }
}; };
render! { rsx! {
h1 { "Login" } h1 { "Login" }
form { onsubmit, form { onsubmit,
input { r#type: "text", id: "username", name: "username" } input { r#type: "text", id: "username", name: "username" }
+1 -1
View File
@@ -63,7 +63,7 @@ fn app() -> Element {
log::debug!("Hello from the app"); log::debug!("Hello from the app");
render! { rsx! {
div { div {
h1 { "Hello, Mobile" } h1 { "Hello, Mobile" }
div { div {
+2 -2
View File
@@ -5,7 +5,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
button { button {
onclick: move |_| { onclick: move |_| {
@@ -19,7 +19,7 @@ fn app() -> Element {
} }
fn popup() -> Element { fn popup() -> Element {
render! { rsx! {
div { "This is a popup!" } div { "This is a popup!" }
} }
} }
+1 -1
View File
@@ -11,7 +11,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
onclick: move |_| println!("clicked! top"), onclick: move |_| println!("clicked! top"),
"- div" "- div"
+1 -1
View File
@@ -49,7 +49,7 @@ fn App() -> Element {
if fermi_auth_request.read().is_none() { if fermi_auth_request.read().is_none() {
*fermi_auth_request.write() = Some(stored_auth_request); *fermi_auth_request.write() = Some(stored_auth_request);
} }
render! { Router::<Route> {} } rsx! { Router::<Route> {} }
} }
fn main() { fn main() {
@@ -24,7 +24,7 @@ pub fn LogOut(cx: Scope<ClientProps>) -> Element {
Some(log_out_url_result) => match log_out_url_result { Some(log_out_url_result) => match log_out_url_result {
Some(uri) => match uri { Some(uri) => match uri {
Ok(uri) => { Ok(uri) => {
render! { rsx! {
Link { Link {
onclick: move |_| { onclick: move |_| {
{ {
@@ -40,11 +40,11 @@ pub fn LogOut(cx: Scope<ClientProps>) -> Element {
} }
} }
Err(error) => { Err(error) => {
render! { div { "Failed to load disconnection url: {error:?}" } } rsx! { div { "Failed to load disconnection url: {error:?}" } }
} }
}, },
None => { None => {
render! { div { "Loading... Please wait" } } rsx! { div { "Loading... Please wait" } }
} }
}, },
None => { None => {
@@ -59,15 +59,15 @@ pub fn LogOut(cx: Scope<ClientProps>) -> Element {
}) })
}; };
logout_url_task(); logout_url_task();
render! { div { "Loading log out url... Please wait" } } rsx! { div { "Loading log out url... Please wait" } }
} }
}, },
None => { None => {
render! {{}} rsx! {{}}
} }
}, },
None => { None => {
render! {{}} rsx! {{}}
} }
}) })
} }
@@ -113,14 +113,14 @@ pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
}) })
}; };
exchange_refresh_token_spawn(); exchange_refresh_token_spawn();
render! { div { "Refreshing session, please wait" } } rsx! { div { "Refreshing session, please wait" } }
} }
None => { None => {
render! { div { "Id token expired and no refresh token found" } } rsx! { div { "Id token expired and no refresh token found" } }
} }
}, },
None => { None => {
render! {{}} rsx! {{}}
} }
}) })
} }
@@ -135,21 +135,21 @@ pub fn LoadClient() -> Element {
*fermi_client.write() = ClientState { *fermi_client.write() = ClientState {
oidc_client: Some(ClientProps::new(client_id.clone(), client.clone())), oidc_client: Some(ClientProps::new(client_id.clone(), client.clone())),
}; };
render! { rsx! {
div { "Client successfully loaded" } div { "Client successfully loaded" }
Outlet::<Route> {} Outlet::<Route> {}
} }
} }
Err(error) => { Err(error) => {
log::info! {"Failed to load client: {:?}", error}; log::info! {"Failed to load client: {:?}", error};
render! { rsx! {
div { "Failed to load client: {error:?}" } div { "Failed to load client: {error:?}" }
Outlet::<Route> {} Outlet::<Route> {}
} }
} }
}, },
None => { None => {
render! { rsx! {
div { div {
div { "Loading client, please wait" } div { "Loading client, please wait" }
Outlet::<Route> {} Outlet::<Route> {}
@@ -180,7 +180,7 @@ pub fn AuthHeader() -> Element {
auth_request.nonce.clone(), auth_request.nonce.clone(),
) { ) {
Ok(email) => { Ok(email) => {
render! { rsx! {
div { div {
div { {email} } div { {email} }
LogOut { client_id: client_props.client_id, client: client_props.client } LogOut { client_id: client_props.client_id, client: client_props.client }
@@ -193,7 +193,7 @@ pub fn AuthHeader() -> Element {
// Id token failed to be decoded because it expired, we refresh it // Id token failed to be decoded because it expired, we refresh it
openidconnect::ClaimsVerificationError::Expired(_message) => { openidconnect::ClaimsVerificationError::Expired(_message) => {
log::info!("Token expired"); log::info!("Token expired");
render! { rsx! {
div { div {
RefreshToken { client_id: client_props.client_id, client: client_props.client } RefreshToken { client_id: client_props.client_id, client: client_props.client }
Outlet::<Route> {} Outlet::<Route> {}
@@ -203,7 +203,7 @@ pub fn AuthHeader() -> Element {
// Other issue with token decoding // Other issue with token decoding
_ => { _ => {
log::info!("Other issue with token"); log::info!("Other issue with token");
render! { rsx! {
div { div {
div { "{error}" } div { "{error}" }
Outlet::<Route> {} Outlet::<Route> {}
@@ -215,7 +215,7 @@ pub fn AuthHeader() -> Element {
} }
// User is not logged in // User is not logged in
None => { None => {
render! { rsx! {
div { div {
Link { to: auth_request.authorize_url.clone(), "Log in" } Link { to: auth_request.authorize_url.clone(), "Log in" }
Outlet::<Route> {} Outlet::<Route> {}
@@ -232,17 +232,17 @@ pub fn AuthHeader() -> Element {
auth_request: Some(auth_request), auth_request: Some(auth_request),
}), }),
); );
render! { div { "Loading nonce" } } rsx! { div { "Loading nonce" } }
} }
} }
} }
// Client is not initialized yet, we need it for everything // Client is not initialized yet, we need it for everything
(None, _, _) => { (None, _, _) => {
render! { LoadClient {} } rsx! { LoadClient {} }
} }
// We need everything loaded before doing anything // We need everything loaded before doing anything
(_client, _auth_request, _auth_token) => { (_client, _auth_request, _auth_token) => {
render! {{}} rsx! {{}}
} }
}) })
} }
@@ -1,5 +1,5 @@
use dioxus::prelude::*; use dioxus::prelude::*;
pub fn Home() -> Element { pub fn Home() -> Element {
render! { div { "Hello world" } } rsx! { div { "Hello world" } }
} }
@@ -21,14 +21,14 @@ pub fn Login(query_string: String) -> Element {
(Some(client_props), Some(auth_token_read)) => { (Some(client_props), Some(auth_token_read)) => {
match (auth_token_read.id_token, auth_token_read.refresh_token) { match (auth_token_read.id_token, auth_token_read.refresh_token) {
(Some(_id_token), Some(_refresh_token)) => { (Some(_id_token), Some(_refresh_token)) => {
render! { rsx! {
div { "Sign in successful" } div { "Sign in successful" }
Link { to: home_url, "Go back home" } Link { to: home_url, "Go back home" }
} }
} }
// If the refresh token is set but not the id_token, there was an error, we just go back home and reset their value // If the refresh token is set but not the id_token, there was an error, we just go back home and reset their value
(None, Some(_)) | (Some(_), None) => { (None, Some(_)) | (Some(_), None) => {
render! { rsx! {
div { "Error while attempting to log in" } div { "Error while attempting to log in" }
Link { Link {
to: home_url, to: home_url,
@@ -70,17 +70,17 @@ pub fn Login(query_string: String) -> Element {
}) })
}; };
token_response_spawn(); token_response_spawn();
render!{ div {} } rsx!{ div {} }
} }
None => { None => {
render! { div { "No code provided" } } rsx! { div { "No code provided" } }
} }
} }
} }
} }
} }
(_, _) => { (_, _) => {
render! {{}} rsx! {{}}
} }
}) })
} }
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
#[component] #[component]
pub fn NotFound(route: Vec<String>) -> Element { pub fn NotFound(route: Vec<String>) -> Element {
render! { rsx! {
div{ div{
{route.join("")} {route.join("")}
} }
+2 -2
View File
@@ -11,7 +11,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
Button { Button {
a: "asd".to_string(), a: "asd".to_string(),
c: "asd".to_string(), c: "asd".to_string(),
@@ -52,7 +52,7 @@ struct ButtonProps {
} }
fn Button(props: ButtonProps) -> Element { fn Button(props: ButtonProps) -> Element {
render! { rsx! {
button { button {
"{props.a} | " "{props.a} | "
"{props.b:?} | " "{props.b:?} | "
+1 -1
View File
@@ -6,7 +6,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
width: "100%", width: "100%",
height: "100%", height: "100%",
+2 -2
View File
@@ -40,7 +40,7 @@ const STYLE: &str = include_str!("./assets/calculator.css");
fn app() -> Element { fn app() -> Element {
let mut state = use_signal(Calculator::new); let mut state = use_signal(Calculator::new);
render! { rsx! {
style { {STYLE} } style { {STYLE} }
div { id: "wrapper", div { id: "wrapper",
div { class: "app", div { class: "app",
@@ -98,7 +98,7 @@ fn app() -> Element {
#[component] #[component]
fn CalculatorKey(name: String, onclick: EventHandler<MouseEvent>, children: Element) -> Element { fn CalculatorKey(name: String, onclick: EventHandler<MouseEvent>, children: Element) -> Element {
render! { rsx! {
button { class: "calculator-key {name}", onclick: move |e| onclick.call(e), {&children} } button { class: "calculator-key {name}", onclick: move |e| onclick.call(e), {&children} }
} }
} }
+1 -1
View File
@@ -14,7 +14,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut state = use_signal(|| PlayerState { is_playing: false }); let mut state = use_signal(|| PlayerState { is_playing: false });
render!( rsx!(
div { div {
h1 {"Select an option"} h1 {"Select an option"}
h3 { "The radio is... ", {state.read().is_playing()}, "!" } h3 { "The radio is... ", {state.read().is_playing()}, "!" }
+3 -3
View File
@@ -64,7 +64,7 @@ impl FromQuery for ManualBlogQuerySegments {
#[component] #[component]
fn BlogPost(query_params: ManualBlogQuerySegments) -> Element { fn BlogPost(query_params: ManualBlogQuerySegments) -> Element {
render! { rsx! {
div{"This is your blogpost with a query segment:"} div{"This is your blogpost with a query segment:"}
div{ "{query_params:?}" } div{ "{query_params:?}" }
} }
@@ -72,7 +72,7 @@ fn BlogPost(query_params: ManualBlogQuerySegments) -> Element {
#[component] #[component]
fn AutomaticBlogPost(name: String, surname: String) -> Element { fn AutomaticBlogPost(name: String, surname: String) -> Element {
render! { rsx! {
div{"This is your blogpost with a query segment:"} div{"This is your blogpost with a query segment:"}
div{ "name={name}&surname={surname}" } div{ "name={name}&surname={surname}" }
} }
@@ -80,7 +80,7 @@ fn AutomaticBlogPost(name: String, surname: String) -> Element {
#[component] #[component]
fn App() -> Element { fn App() -> Element {
render! { Router::<Route>{} } rsx! { Router::<Route>{} }
} }
fn main() { fn main() {
+1 -1
View File
@@ -38,7 +38,7 @@ fn app() -> Element {
} }
}; };
render!( rsx!(
div { div {
width: "50%", width: "50%",
height: "50%", height: "50%",
+1 -1
View File
@@ -11,7 +11,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut count = use_signal(|| 0); let mut count = use_signal(|| 0);
render! { rsx! {
h1 { "High-Five counter: {count}" } h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" } button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" } button { onclick: move |_| count -= 1, "Down low!" }
+6 -6
View File
@@ -34,7 +34,7 @@ enum Route {
#[component] #[component]
fn NavBar() -> Element { fn NavBar() -> Element {
render! { rsx! {
nav { nav {
ul { ul {
li { li {
@@ -51,12 +51,12 @@ fn NavBar() -> Element {
#[component] #[component]
fn Home() -> Element { fn Home() -> Element {
render! { h1 { "Welcome to the Dioxus Blog!" } } rsx! { h1 { "Welcome to the Dioxus Blog!" } }
} }
#[component] #[component]
fn Blog() -> Element { fn Blog() -> Element {
render! { rsx! {
h1 { "Blog" } h1 { "Blog" }
Outlet::<Route> {} Outlet::<Route> {}
} }
@@ -64,7 +64,7 @@ fn Blog() -> Element {
#[component] #[component]
fn BlogList() -> Element { fn BlogList() -> Element {
render! { rsx! {
h2 { "Choose a post" } h2 { "Choose a post" }
ul { ul {
li { li {
@@ -89,12 +89,12 @@ fn BlogList() -> Element {
#[component] #[component]
fn BlogPost(name: String) -> Element { fn BlogPost(name: String) -> Element {
render! { h2 { "Blog Post: {name}" } } rsx! { h2 { "Blog Post: {name}" } }
} }
#[component] #[component]
fn PageNotFound(route: Vec<String>) -> Element { fn PageNotFound(route: Vec<String>) -> Element {
render! { rsx! {
h1 { "Page not found" } h1 { "Page not found" }
p { "We are terribly sorry, but the page you requested doesn't exist." } p { "We are terribly sorry, but the page you requested doesn't exist." }
pre { color: "red", "log:\nattemped to navigate to: {route:?}" } pre { color: "red", "log:\nattemped to navigate to: {route:?}" }
+19 -19
View File
@@ -1,7 +1,7 @@
//! A tour of the render! macro //! A tour of the rsx! macro
//! ------------------------ //! ------------------------
//! //!
//! This example serves as an informal quick reference of all the things that the render! macro can do. //! This example serves as an informal quick reference of all the things that the rsx! macro can do.
//! //!
//! A full in-depth reference guide is available at: https://www.notion.so/rsx-macro-basics-ef6e367dec124f4784e736d91b0d0b19 //! A full in-depth reference guide is available at: https://www.notion.so/rsx-macro-basics-ef6e367dec124f4784e736d91b0d0b19
//! //!
@@ -55,7 +55,7 @@ fn main() {
// let formatting_tuple = ("a", "b"); // let formatting_tuple = ("a", "b");
// let lazy_fmt = format_args!("lazily formatted text"); // let lazy_fmt = format_args!("lazily formatted text");
// let asd = 123; // let asd = 123;
// render! { // rsx! {
// div { // div {
// // Elements // // Elements
// div {} // div {}
@@ -95,10 +95,10 @@ fn main() {
// } // }
// // Expressions can be used in element position too: // // Expressions can be used in element position too:
// {render!(p { "More templating!" })}, // {rsx!(p { "More templating!" })},
// // Iterators // // Iterators
// {(0..10).map(|i| render!(li { "{i}" }))}, // {(0..10).map(|i| rsx!(li { "{i}" }))},
// // Iterators within expressions // // Iterators within expressions
// { // {
@@ -106,19 +106,19 @@ fn main() {
// // Iterators *should* have keys when you can provide them. // // Iterators *should* have keys when you can provide them.
// // Keys make your app run faster. Make sure your keys are stable, unique, and predictable. // // Keys make your app run faster. Make sure your keys are stable, unique, and predictable.
// // Using an "ID" associated with your data is a good idea. // // Using an "ID" associated with your data is a good idea.
// data.into_iter().map(|(k, v)| render!(li { key: "{k}", "{v}" })) // data.into_iter().map(|(k, v)| rsx!(li { key: "{k}", "{v}" }))
// } // }
// // Matching // // Matching
// match true { // match true {
// true => render!( h1 {"Top text"}), // true => rsx!( h1 {"Top text"}),
// false => render!( h1 {"Bottom text"}) // false => rsx!( h1 {"Bottom text"})
// } // }
// // Conditional rendering // // Conditional rendering
// // Dioxus conditional rendering is based around None/Some. We have no special syntax for conditionals. // // Dioxus conditional rendering is based around None/Some. We have no special syntax for conditionals.
// // You can convert a bool condition to render! with .then and .or // // You can convert a bool condition to rsx! with .then and .or
// {true.then(|| render!(div {}))}, // {true.then(|| rsx!(div {}))},
// // Alternatively, you can use the "if" syntax - but both branches must be resolve to Element // // Alternatively, you can use the "if" syntax - but both branches must be resolve to Element
// if false { // if false {
@@ -130,7 +130,7 @@ fn main() {
// // Using optionals for diverging branches // // Using optionals for diverging branches
// // Note that since this is wrapped in curlies, it's interpreted as an expression // // Note that since this is wrapped in curlies, it's interpreted as an expression
// {if true { // {if true {
// Some(render!(h1 {"Top text"})) // Some(rsx!(h1 {"Top text"}))
// } else { // } else {
// None // None
// }} // }}
@@ -172,7 +172,7 @@ fn main() {
// // Can pass in props directly as an expression // // Can pass in props directly as an expression
// { // {
// let props = TallerProps {a: "hello", children: None }; // let props = TallerProps {a: "hello", children: None };
// render!(Taller { ..props }) // rsx!(Taller { ..props })
// } // }
// // Spreading can also be overridden manually // // Spreading can also be overridden manually
@@ -225,7 +225,7 @@ fn main() {
// } // }
// fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element { // fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element {
// render! { // rsx! {
// p { "{text}" } // p { "{text}" }
// } // }
// } // }
@@ -235,7 +235,7 @@ fn main() {
// // something like Clippy. // // something like Clippy.
// #[component(no_case_check)] // #[component(no_case_check)]
// fn lowercase_helper() -> Element { // fn lowercase_helper() -> Element {
// render! { // rsx! {
// "asd" // "asd"
// } // }
// } // }
@@ -254,18 +254,18 @@ fn main() {
// // something like Clippy. // // something like Clippy.
// #[component(no_case_check)] // #[component(no_case_check)]
// pub fn lowercase_component() -> Element { // pub fn lowercase_component() -> Element {
// render! { "look ma, no uppercase" } // rsx! { "look ma, no uppercase" }
// } // }
// } // }
// /// Documention for this component is visible within the rsx macro // /// Documention for this component is visible within the rsx macro
// #[component] // #[component]
// pub fn Taller( // pub fn Taller(
// /// Fields are documented and accessible in render! // /// Fields are documented and accessible in rsx!
// a: &'static str, // a: &'static str,
// children: Element, // children: Element,
// ) -> Element { // ) -> Element {
// render! { {&children} } // rsx! { {&children} }
// } // }
// #[derive(Props, PartialEq, Eq)] // #[derive(Props, PartialEq, Eq)]
@@ -285,7 +285,7 @@ fn main() {
// #[component] // #[component]
// fn WithInline(cx: Scope<'a>, text: &'a str) -> Element { // fn WithInline(cx: Scope<'a>, text: &'a str) -> Element {
// render! { // rsx! {
// p { "{text}" } // p { "{text}" }
// } // }
// } // }
@@ -295,7 +295,7 @@ fn main() {
// where // where
// T: Display, // T: Display,
// { // {
// render! { // rsx! {
// p { "{text}" } // p { "{text}" }
// } // }
// } // }
+1 -1
View File
@@ -7,7 +7,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut header_element = use_signal(|| None); let mut header_element = use_signal(|| None);
render! { rsx! {
div { div {
h1 { h1 {
onmounted: move |cx| header_element.set(Some(cx.inner().clone())), onmounted: move |cx| header_element.set(Some(cx.inner().clone())),
+1 -1
View File
@@ -10,5 +10,5 @@ fn app() -> Element {
_ = use_global_shortcut("ctrl+s", move || toggled.toggle()); _ = use_global_shortcut("ctrl+s", move || toggled.toggle());
render!("toggle: {toggled}") rsx!("toggle: {toggled}")
} }
+3 -3
View File
@@ -14,10 +14,10 @@ fn app() -> Element {
// todo: i'd like it for children on elements to be inferred as the children of the element // todo: i'd like it for children on elements to be inferred as the children of the element
// also should shorthands understand references/dereferences? // also should shorthands understand references/dereferences?
// ie **a, *a, &a, &mut a, etc // ie **a, *a, &a, &mut a, etc
let children = render! { "Child" }; let children = rsx! { "Child" };
let onclick = move |_| println!("Clicked!"); let onclick = move |_| println!("Clicked!");
render! { rsx! {
div { class, id, {&children} } div { class, id, {&children} }
Component { a, b, c, children, onclick } Component { a, b, c, children, onclick }
Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: None, onclick: Default::default() } } Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: None, onclick: Default::default() } }
@@ -26,7 +26,7 @@ fn app() -> Element {
#[component] #[component]
fn Component(a: i32, b: i32, c: i32, children: Element, onclick: EventHandler<()>) -> Element { fn Component(a: i32, b: i32, c: i32, children: Element, onclick: EventHandler<()>) -> Element {
render! { rsx! {
div { "{a}" } div { "{a}" }
div { "{b}" } div { "{b}" }
div { "{c}" } div { "{c}" }
+1 -1
View File
@@ -26,7 +26,7 @@ fn app() -> Element {
} }
}); });
render! { rsx! {
h1 { "High-Five counter: {count}" } h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" } button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" } button { onclick: move |_| count -= 1, "Down low!" }
+5 -5
View File
@@ -32,7 +32,7 @@ enum Route {
#[component] #[component]
fn NavBar() -> Element { fn NavBar() -> Element {
render! { rsx! {
h1 { "Your app here" } h1 { "Your app here" }
ul { ul {
li { li {
@@ -73,20 +73,20 @@ fn NavBar() -> Element {
#[component] #[component]
fn Home() -> Element { fn Home() -> Element {
log::debug!("rendering home {:?}", current_scope_id()); log::debug!("rendering home {:?}", current_scope_id());
render! { h1 { "Home" } } rsx! { h1 { "Home" } }
} }
#[component] #[component]
fn BlogList() -> Element { fn BlogList() -> Element {
log::debug!("rendering blog list {:?}", current_scope_id()); log::debug!("rendering blog list {:?}", current_scope_id());
render! { div { "Blog List" } } rsx! { div { "Blog List" } }
} }
#[component] #[component]
fn BlogPost(post: String) -> Element { fn BlogPost(post: String) -> Element {
log::debug!("rendering blog post {}", post); log::debug!("rendering blog post {}", post);
render! { rsx! {
div { div {
h3 { "blog post: {post}" } h3 { "blog post: {post}" }
Link { to: Route::BlogList {}, "back to blog list" } Link { to: Route::BlogList {}, "back to blog list" }
@@ -96,5 +96,5 @@ fn BlogPost(post: String) -> Element {
#[component] #[component]
fn Oranges() -> Element { fn Oranges() -> Element {
render!("Oranges are not apples!") rsx!("Oranges are not apples!")
} }
+4 -4
View File
@@ -5,20 +5,20 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render!( rsx!(
div { div {
// Use Map directly to lazily pull elements // Use Map directly to lazily pull elements
{(0..10).map(|f| render! { "{f}" })}, {(0..10).map(|f| rsx! { "{f}" })},
// Collect into an intermediate collection if necessary, and call into_iter // Collect into an intermediate collection if necessary, and call into_iter
{["a", "b", "c", "d", "e", "f"] {["a", "b", "c", "d", "e", "f"]
.into_iter() .into_iter()
.map(|f| render! { "{f}" }) .map(|f| rsx! { "{f}" })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter()}, .into_iter()},
// Use optionals // Use optionals
{Some(render! { "Some" })}, {Some(rsx! { "Some" })},
// use a for loop where the body itself is RSX // use a for loop where the body itself is RSX
for name in 0..10 { for name in 0..10 {
+3 -3
View File
@@ -14,12 +14,12 @@ enum Route {
#[component] #[component]
fn Homepage() -> Element { fn Homepage() -> Element {
render! { h1 { "Welcome home" } } rsx! { h1 { "Welcome home" } }
} }
#[component] #[component]
fn Blog(id: String) -> Element { fn Blog(id: String) -> Element {
render! { rsx! {
h1 { "How to make: " } h1 { "How to make: " }
p { "{id}" } p { "{id}" }
} }
@@ -27,7 +27,7 @@ fn Blog(id: String) -> Element {
#[component] #[component]
fn Nav() -> Element { fn Nav() -> Element {
render! { rsx! {
nav { nav {
li { li {
Link { to: Route::Homepage {}, "Go home" } Link { to: Route::Homepage {}, "Go home" }
+2 -2
View File
@@ -8,7 +8,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
spreadable_component { spreadable_component {
width: "10px", width: "10px",
extra_data: "hello{1}", extra_data: "hello{1}",
@@ -20,7 +20,7 @@ fn app() -> Element {
} }
fn spreadable_component(props: Props) -> Element { fn spreadable_component(props: Props) -> Element {
render! { rsx! {
audio { ..props.attributes, "1: {props.extra_data}\n2: {props.extra_data2}" } audio { ..props.attributes, "1: {props.extra_data}\n2: {props.extra_data2}" }
} }
} }
+3 -3
View File
@@ -9,10 +9,10 @@ fn main() {
let mut vdom = VirtualDom::prebuilt(app); let mut vdom = VirtualDom::prebuilt(app);
println!("{}", dioxus_ssr::render(&vdom)); println!("{}", dioxus_ssr::render(&vdom));
// Or we can render render! calls themselves // Or we can render rsx! calls themselves
println!( println!(
"{}", "{}",
dioxus_ssr::render_element(render! { dioxus_ssr::render_element(rsx! {
div { div {
h1 { "Hello, world!" } h1 { "Hello, world!" }
} }
@@ -30,7 +30,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render!( rsx!(
div { div {
h1 { "Title" } h1 { "Title" }
p { "Body" } p { "Body" }
+1 -1
View File
@@ -18,7 +18,7 @@ fn app() -> Element {
} }
}); });
render! { rsx! {
h1 { "High-Five counter: {count}" } h1 { "High-Five counter: {count}" }
} }
} }
+5 -5
View File
@@ -2,7 +2,7 @@
//! Suspense in Dioxus //! Suspense in Dioxus
//! //!
//! Currently, `render!` does not accept futures as values. To achieve the functionality //! Currently, `rsx!` does not accept futures as values. To achieve the functionality
//! of suspense, we need to make a new component that performs its own suspense //! of suspense, we need to make a new component that performs its own suspense
//! handling. //! handling.
//! //!
@@ -29,7 +29,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
h1 { "Dogs are very important" } h1 { "Dogs are very important" }
p { p {
@@ -64,11 +64,11 @@ fn Doggo() -> Element {
}); });
match fut.value().read().as_ref() { match fut.value().read().as_ref() {
Some(Ok(resp)) => render! { Some(Ok(resp)) => rsx! {
button { onclick: move |_| fut.restart(), "Click to fetch another doggo" } button { onclick: move |_| fut.restart(), "Click to fetch another doggo" }
div { img { max_width: "500px", max_height: "500px", src: "{resp.message}" } } div { img { max_width: "500px", max_height: "500px", src: "{resp.message}" } }
}, },
Some(Err(_)) => render! { div { "loading dogs failed" } }, Some(Err(_)) => rsx! { div { "loading dogs failed" } },
None => render! { div { "loading dogs..." } }, None => rsx! { div { "loading dogs..." } },
} }
} }
+2 -2
View File
@@ -8,7 +8,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { user_select: "none", webkit_user_select: "none", margin_left: "10%", margin_right: "10%", div { user_select: "none", webkit_user_select: "none", margin_left: "10%", margin_right: "10%",
h1 { "Click die to generate a new value" } h1 { "Click die to generate a new value" }
div { cursor: "pointer", height: "100%", width: "100%", Dice {} } div { cursor: "pointer", height: "100%", width: "100%", Dice {} }
@@ -33,7 +33,7 @@ fn Dice() -> Element {
let mut value = use_signal(|| 5); let mut value = use_signal(|| 5);
let active_dots = use_selector(move || &DOTS_FOR_VALUE[(value() - 1) as usize]); let active_dots = use_selector(move || &DOTS_FOR_VALUE[(value() - 1) as usize]);
render! { rsx! {
svg { svg {
view_box: "-1000 -1000 2000 2000", view_box: "-1000 -1000 2000 2000",
prevent_default: "onclick", prevent_default: "onclick",
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*; use dioxus::prelude::*;
fn app() -> Element { fn app() -> Element {
render! { rsx! {
svg { svg {
width: "200", width: "200",
height: "250", height: "250",
+3 -3
View File
@@ -10,7 +10,7 @@ fn main() {
pub fn app() -> Element { pub fn app() -> Element {
let grey_background = true; let grey_background = true;
render!( rsx!(
div { div {
header { header {
class: "text-gray-400 body-font", class: "text-gray-400 body-font",
@@ -73,7 +73,7 @@ pub fn app() -> Element {
} }
pub fn StacksIcon() -> Element { pub fn StacksIcon() -> Element {
render!( rsx!(
svg { svg {
fill: "none", fill: "none",
stroke: "currentColor", stroke: "currentColor",
@@ -88,7 +88,7 @@ pub fn StacksIcon() -> Element {
} }
pub fn RightArrowIcon() -> Element { pub fn RightArrowIcon() -> Element {
render!( rsx!(
svg { svg {
fill: "none", fill: "none",
stroke: "currentColor", stroke: "currentColor",
+1 -1
View File
@@ -19,7 +19,7 @@ fn app() -> Element {
} }
}); });
render! { rsx! {
div { div {
h1 { "Current count: {count}" } h1 { "Current count: {count}" }
button { onclick: move |_| count.set(0), "Reset the count" } button { onclick: move |_| count.set(0), "Reset the count" }
+1 -1
View File
@@ -9,7 +9,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut model = use_signal(|| String::from("asd")); let mut model = use_signal(|| String::from("asd"));
render! { rsx! {
textarea { textarea {
class: "border", class: "border",
rows: "10", rows: "10",
+5 -5
View File
@@ -45,7 +45,7 @@ pub fn app() -> Element {
filtered_todos filtered_todos
}); });
render! { rsx! {
section { class: "todoapp", section { class: "todoapp",
style { {include_str!("./assets/todomvc.css")} } style { {include_str!("./assets/todomvc.css")} }
TodoHeader { todos } TodoHeader { todos }
@@ -98,7 +98,7 @@ pub fn TodoHeader(mut todos: Signal<HashMap<u32, TodoItem>>) -> Element {
} }
}; };
render! { rsx! {
header { class: "header", header { class: "header",
h1 { "todos" } h1 { "todos" }
input { input {
@@ -119,7 +119,7 @@ pub fn TodoEntry(mut todos: Signal<HashMap<u32, TodoItem>>, id: u32) -> Element
let checked = use_selector(move || todos.read().get(&id).unwrap().checked); let checked = use_selector(move || todos.read().get(&id).unwrap().checked);
let contents = use_selector(move || todos.read().get(&id).unwrap().contents.clone()); let contents = use_selector(move || todos.read().get(&id).unwrap().contents.clone());
render! { rsx! {
li { class: if checked() { "completed" }, class: if is_editing() { "editing" }, li { class: if checked() { "completed" }, class: if is_editing() { "editing" },
div { class: "view", div { class: "view",
input { input {
@@ -168,7 +168,7 @@ pub fn ListFooter(
) -> Element { ) -> Element {
let show_clear_completed = use_selector(move || todos.read().values().any(|todo| todo.checked)); let show_clear_completed = use_selector(move || todos.read().values().any(|todo| todo.checked));
render! { rsx! {
footer { class: "footer", footer { class: "footer",
span { class: "todo-count", span { class: "todo-count",
strong { "{active_todo_count} " } strong { "{active_todo_count} " }
@@ -209,7 +209,7 @@ pub fn ListFooter(
} }
pub fn PageFooter() -> Element { pub fn PageFooter() -> Element {
render! { rsx! {
footer { class: "info", footer { class: "info",
p { "Double-click to edit a todo" } p { "Double-click to edit a todo" }
p { p {
+1 -1
View File
@@ -43,7 +43,7 @@ fn app() -> Element {
}); });
}); });
render! { rsx! {
div { div {
video { video {
src: "/videos/test_video.mp4", src: "/videos/test_video.mp4",
+1 -1
View File
@@ -5,7 +5,7 @@ fn main() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
web-component { web-component {
"my-prop": "5%", "my-prop": "5%",
} }
+1 -1
View File
@@ -18,7 +18,7 @@ fn app() -> Element {
let mut always_on_top = use_signal(|| false); let mut always_on_top = use_signal(|| false);
let mut decorations = use_signal(|| false); let mut decorations = use_signal(|| false);
render!( rsx!(
link { link {
href: "https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", href: "https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css",
rel: "stylesheet" rel: "stylesheet"
+1 -1
View File
@@ -21,7 +21,7 @@ fn app() -> Element {
_ => {} _ => {}
}); });
render! { rsx! {
div { width: "100%", height: "100%", display: "flex", flex_direction: "column", align_items: "center", div { width: "100%", height: "100%", display: "flex", flex_direction: "column", align_items: "center",
if focused() { if focused() {
"This window is focused!" "This window is focused!"
+1 -1
View File
@@ -7,7 +7,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut level = use_signal(|| 1.0); let mut level = use_signal(|| 1.0);
render! { rsx! {
input { input {
r#type: "number", r#type: "number",
value: "{level}", value: "{level}",
+1 -1
View File
@@ -11,7 +11,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
let mut contents = use_signal(|| String::from("<script>alert(\"hello world\")</script>")); let mut contents = use_signal(|| String::from("<script>alert(\"hello world\")</script>"));
render! { rsx! {
div { div {
h1 {"Dioxus is XSS-Safe"} h1 {"Dioxus is XSS-Safe"}
h3 { "{contents}" } h3 { "{contents}" }
@@ -67,11 +67,11 @@
//! //!
//! #[name_changer(CoolName)] //! #[name_changer(CoolName)]
//! pub fn LameName() -> Element { //! pub fn LameName() -> Element {
//! render! { "I want a cool name!" } //! rsx! { "I want a cool name!" }
//! } //! }
//! //!
//! pub fn App() -> Element { //! pub fn App() -> Element {
//! render! { CoolName {} } // Renders: "I want a cool name!" //! rsx! { CoolName {} } // Renders: "I want a cool name!"
//! } //! }
//! ``` //! ```
//! ## Implementing a component body deserializer //! ## Implementing a component body deserializer
+14 -13
View File
@@ -40,20 +40,21 @@ pub fn derive_typed_builder(input: TokenStream) -> TokenStream {
/// The rsx! macro makes it easy for developers to write jsx-style markup in their components. /// The rsx! macro makes it easy for developers to write jsx-style markup in their components.
#[proc_macro] #[proc_macro]
pub fn rsx(tokens: TokenStream) -> TokenStream { pub fn rsx(tokens: TokenStream) -> TokenStream {
render(tokens) match syn::parse::<rsx::CallBody>(tokens) {
}
/// The render! macro makes it easy for developers to write jsx-style markup in their components.
///
/// The render macro automatically renders rsx - making it unhygienic.
#[proc_macro]
pub fn render(s: TokenStream) -> TokenStream {
match syn::parse::<rsx::CallBody>(s) {
Err(err) => err.to_compile_error().into(), Err(err) => err.to_compile_error().into(),
Ok(body) => RenderCallBody(body).into_token_stream().into(), Ok(body) => RenderCallBody(body).into_token_stream().into(),
} }
} }
/// The rsx! macro makes it easy for developers to write jsx-style markup in their components.
///
/// The render macro automatically renders rsx - making it unhygienic.
#[deprecated(note = "Use `rsx!` instead.")]
#[proc_macro]
pub fn render(tokens: TokenStream) -> TokenStream {
rsx(tokens)
}
/// Derive props for a component within the component definition. /// Derive props for a component within the component definition.
/// ///
/// This macro provides a simple transformation from `Scope<{}>` to `Scope<P>`, /// This macro provides a simple transformation from `Scope<{}>` to `Scope<P>`,
@@ -129,7 +130,7 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// ```rust,ignore /// ```rust,ignore
/// #[component] /// #[component]
/// fn GreetBob() -> Element { /// fn GreetBob() -> Element {
/// render! { "hello, bob" } /// rsx! { "hello, bob" }
/// } /// }
/// ///
/// // is equivalent to /// // is equivalent to
@@ -139,7 +140,7 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// #[warn(non_snake_case)] /// #[warn(non_snake_case)]
/// #[inline(always)] /// #[inline(always)]
/// fn __dx_inner_comp() -> Element { /// fn __dx_inner_comp() -> Element {
/// render! { "hello, bob" } /// rsx! { "hello, bob" }
/// } /// }
/// // There's no function call overhead since __dx_inner_comp has the #[inline(always)] attribute, /// // There's no function call overhead since __dx_inner_comp has the #[inline(always)] attribute,
/// // so don't worry about performance. /// // so don't worry about performance.
@@ -150,7 +151,7 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// ```rust,ignore /// ```rust,ignore
/// #[component(no_case_check)] /// #[component(no_case_check)]
/// fn GreetPerson(person: String) -> Element { /// fn GreetPerson(person: String) -> Element {
/// render! { "hello, {person}" } /// rsx! { "hello, {person}" }
/// } /// }
/// ///
/// // is equivalent to /// // is equivalent to
@@ -168,7 +169,7 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// fn __dx_inner_comp(props: GreetPersonProps>e) -> Element { /// fn __dx_inner_comp(props: GreetPersonProps>e) -> Element {
/// let GreetPersonProps { person } = &cx.props; /// let GreetPersonProps { person } = &cx.props;
/// { /// {
/// render! { "hello, {person}" } /// rsx! { "hello, {person}" }
/// } /// }
/// } /// }
/// ///
+3 -3
View File
@@ -75,7 +75,7 @@ where
/// ///
/// ```rust /// ```rust
/// fn app() -> Element { /// fn app() -> Element {
/// render! { /// rsx! {
/// div {} /// div {}
/// } /// }
/// } /// }
@@ -90,7 +90,7 @@ where
/// } /// }
/// ///
/// fn app(props: MyProps) -> Element { /// fn app(props: MyProps) -> Element {
/// render! { /// rsx! {
/// div { /// div {
/// "{props.data}" /// "{props.data}"
/// } /// }
@@ -103,7 +103,7 @@ where
/// ```rust /// ```rust
/// #[component] /// #[component]
/// fn app(data: String) -> Element { /// fn app(data: String) -> Element {
/// render! { /// rsx! {
/// div { /// div {
/// "{data}" /// "{data}"
/// } /// }
+2 -2
View File
@@ -140,7 +140,7 @@ impl Runtime {
/// } /// }
/// ///
/// fn app() -> Element { /// fn app() -> Element {
/// render!{ Component { runtime: Runtime::current().unwrap() } } /// rsx!{ Component { runtime: Runtime::current().unwrap() } }
/// } /// }
/// ///
/// // In a dynamic library /// // In a dynamic library
@@ -158,7 +158,7 @@ impl Runtime {
/// fn Component(cx: ComponentProps) -> Element { /// fn Component(cx: ComponentProps) -> Element {
/// cx.use_hook(|| RuntimeGuard::new(cx.runtime.clone())); /// cx.use_hook(|| RuntimeGuard::new(cx.runtime.clone()));
/// ///
/// render! { div {} } /// rsx! { div {} }
/// } /// }
/// ``` /// ```
pub struct RuntimeGuard(()); pub struct RuntimeGuard(());
+2 -2
View File
@@ -176,12 +176,12 @@ impl ScopeContext {
/// ///
/// static app: Component = |cx| { /// static app: Component = |cx| {
/// cx.use_hook(|| cx.provide_context(SharedState("world"))); /// cx.use_hook(|| cx.provide_context(SharedState("world")));
/// render!(Child {}) /// rsx!(Child {})
/// } /// }
/// ///
/// static Child: Component = |cx| { /// static Child: Component = |cx| {
/// let state = cx.consume_state::<SharedState>(); /// let state = cx.consume_state::<SharedState>();
/// render!(div { "hello {state.0}" }) /// rsx!(div { "hello {state.0}" })
/// } /// }
/// ``` /// ```
pub fn provide_context<T: 'static + Clone>(&self, value: T) -> T { pub fn provide_context<T: 'static + Clone>(&self, value: T) -> T {
+2 -2
View File
@@ -10,8 +10,8 @@ fn attrs_cycle() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
let id = generation(); let id = generation();
match id % 2 { match id % 2 {
0 => render! { div {} }, 0 => rsx! { div {} },
1 => render! { 1 => rsx! {
div { h1 { class: "{id}", id: "{id}" } } div { h1 { class: "{id}", id: "{id}" } }
}, },
_ => unreachable!(), _ => unreachable!(),
+1 -1
View File
@@ -3,7 +3,7 @@ use dioxus::prelude::*;
#[test] #[test]
fn bool_test() { fn bool_test() {
let mut app = VirtualDom::new(|| render!(div { hidden: false })); let mut app = VirtualDom::new(|| rsx!(div { hidden: false }));
assert_eq!( assert_eq!(
app.rebuild_to_vec().santize().edits, app.rebuild_to_vec().santize().edits,
+1 -1
View File
@@ -11,7 +11,7 @@ fn app() -> Element {
let value = raw.parse::<f32>().unwrap_or(123.123); let value = raw.parse::<f32>().unwrap_or(123.123);
render! { div { "hello {value}" } } rsx! { div { "hello {value}" } }
} }
#[test] #[test]
+3 -3
View File
@@ -6,16 +6,16 @@ fn state_shares() {
fn app() -> Element { fn app() -> Element {
provide_context(generation() as i32); provide_context(generation() as i32);
render!(child_1 {}) rsx!(child_1 {})
} }
fn child_1() -> Element { fn child_1() -> Element {
render!(child_2 {}) rsx!(child_2 {})
} }
fn child_2() -> Element { fn child_2() -> Element {
let value = consume_context::<i32>().unwrap(); let value = consume_context::<i32>().unwrap();
render!("Value is {value}") rsx!("Value is {value}")
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
+7 -7
View File
@@ -12,7 +12,7 @@ use dioxus_core::ElementId;
#[test] #[test]
fn test_original_diff() { fn test_original_diff() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
div { div { "Hello, world!" } } div { div { "Hello, world!" } }
} }
}); });
@@ -32,7 +32,7 @@ fn test_original_diff() {
#[test] #[test]
fn create() { fn create() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
div { div {
div { div {
"Hello, world!" "Hello, world!"
@@ -75,7 +75,7 @@ fn create() {
#[test] #[test]
fn create_list() { fn create_list() {
let mut dom = VirtualDom::new(|| render! {{(0..3).map(|f| render!( div { "hello" } ))}}); let mut dom = VirtualDom::new(|| rsx! {{(0..3).map(|f| rsx!( div { "hello" } ))}});
let _edits = dom.rebuild_to_vec().santize(); let _edits = dom.rebuild_to_vec().santize();
@@ -95,7 +95,7 @@ fn create_list() {
#[test] #[test]
fn create_simple() { fn create_simple() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
div {} div {}
div {} div {}
div {} div {}
@@ -122,7 +122,7 @@ fn create_simple() {
#[test] #[test]
fn create_components() { fn create_components() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
Child { "abc1" } Child { "abc1" }
Child { "abc2" } Child { "abc2" }
Child { "abc3" } Child { "abc3" }
@@ -135,7 +135,7 @@ fn create_components() {
} }
fn Child(cx: ChildProps) -> Element { fn Child(cx: ChildProps) -> Element {
render! { rsx! {
h1 {} h1 {}
div { {cx.children} } div { {cx.children} }
p {} p {}
@@ -150,7 +150,7 @@ fn create_components() {
#[test] #[test]
fn anchors() { fn anchors() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
if true { if true {
div { "hello" } div { "hello" }
} }
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus::prelude::*;
#[test] #[test]
fn multiroot() { fn multiroot() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
div { "Hello a" } div { "Hello a" }
div { "Hello b" } div { "Hello b" }
div { "Hello c" } div { "Hello c" }
+10 -10
View File
@@ -7,7 +7,7 @@ use dioxus_core::ElementId;
#[test] #[test]
fn empty_fragment_creates_nothing() { fn empty_fragment_creates_nothing() {
fn app() -> Element { fn app() -> Element {
render!({ () }) rsx!({ () })
} }
let mut vdom = VirtualDom::new(app); let mut vdom = VirtualDom::new(app);
@@ -25,7 +25,7 @@ fn empty_fragment_creates_nothing() {
#[test] #[test]
fn root_fragments_work() { fn root_fragments_work() {
let mut vdom = VirtualDom::new(|| { let mut vdom = VirtualDom::new(|| {
render!( rsx!(
div { "hello" } div { "hello" }
div { "goodbye" } div { "goodbye" }
) )
@@ -40,16 +40,16 @@ fn root_fragments_work() {
#[test] #[test]
fn fragments_nested() { fn fragments_nested() {
let mut vdom = VirtualDom::new(|| { let mut vdom = VirtualDom::new(|| {
render!( rsx!(
div { "hello" } div { "hello" }
div { "goodbye" } div { "goodbye" }
{render! { {rsx! {
div { "hello" } div { "hello" }
div { "goodbye" } div { "goodbye" }
{render! { {rsx! {
div { "hello" } div { "hello" }
div { "goodbye" } div { "goodbye" }
{render! { {rsx! {
div { "hello" } div { "hello" }
div { "goodbye" } div { "goodbye" }
}} }}
@@ -67,7 +67,7 @@ fn fragments_nested() {
#[test] #[test]
fn fragments_across_components() { fn fragments_across_components() {
fn app() -> Element { fn app() -> Element {
render! { rsx! {
demo_child {} demo_child {}
demo_child {} demo_child {}
demo_child {} demo_child {}
@@ -77,7 +77,7 @@ fn fragments_across_components() {
fn demo_child() -> Element { fn demo_child() -> Element {
let world = "world"; let world = "world";
render! { "hellO!", {world} } rsx! { "hellO!", {world} }
} }
assert_eq!( assert_eq!(
@@ -89,9 +89,9 @@ fn fragments_across_components() {
#[test] #[test]
fn list_fragments() { fn list_fragments() {
fn app() -> Element { fn app() -> Element {
render!( rsx!(
h1 { "hello" } h1 { "hello" }
{(0..6).map(|f| render!( span { "{f}" }))} {(0..6).map(|f| rsx!( span { "{f}" }))}
) )
} }
assert_eq!( assert_eq!(
+2 -2
View File
@@ -5,11 +5,11 @@ use dioxus_core::ElementId;
// A real-world usecase of templates at peak performance // A real-world usecase of templates at peak performance
// In react, this would be a lot of node creation. // In react, this would be a lot of node creation.
// //
// In Dioxus, we memoize the render! body and simplify it down to a few template loads // In Dioxus, we memoize the rsx! body and simplify it down to a few template loads
// //
// Also note that the IDs increase linearly. This lets us drive a vec on the renderer for O(1) re-indexing // Also note that the IDs increase linearly. This lets us drive a vec on the renderer for O(1) re-indexing
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
for i in 0..3 { for i in 0..3 {
div { div {
+5 -5
View File
@@ -6,7 +6,7 @@ use dioxus_core::ElementId;
#[test] #[test]
fn nested_passthru_creates() { fn nested_passthru_creates() {
fn app() -> Element { fn app() -> Element {
render! { rsx! {
PassThru { PassThru {
PassThru { PassThru {
PassThru { div { "hi" } } PassThru { div { "hi" } }
@@ -17,7 +17,7 @@ fn nested_passthru_creates() {
#[component] #[component]
fn PassThru(children: Element) -> Element { fn PassThru(children: Element) -> Element {
render!({ children }) rsx!({ children })
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -38,7 +38,7 @@ fn nested_passthru_creates() {
#[test] #[test]
fn nested_passthru_creates_add() { fn nested_passthru_creates_add() {
fn app() -> Element { fn app() -> Element {
render! { rsx! {
ChildComp { ChildComp {
"1" "1"
ChildComp { ChildComp {
@@ -54,7 +54,7 @@ fn nested_passthru_creates_add() {
#[component] #[component]
fn ChildComp(children: Element) -> Element { fn ChildComp(children: Element) -> Element {
render! {{children}} rsx! {{children}}
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -81,7 +81,7 @@ fn dynamic_node_as_root() {
fn app() -> Element { fn app() -> Element {
let a = 123; let a = 123;
let b = 456; let b = 456;
render! { "{a}", "{b}" } rsx! { "{a}", "{b}" }
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
+2 -2
View File
@@ -5,8 +5,8 @@ use dioxus::prelude::*;
#[test] #[test]
fn cycling_elements() { fn cycling_elements() {
let mut dom = VirtualDom::new(|| match generation() % 2 { let mut dom = VirtualDom::new(|| match generation() % 2 {
0 => render! { div { "wasd" } }, 0 => rsx! { div { "wasd" } },
1 => render! { div { "abcd" } }, 1 => rsx! { div { "abcd" } },
_ => unreachable!(), _ => unreachable!(),
}); });
+11 -11
View File
@@ -13,46 +13,46 @@ fn component_swap() {
render_phase += 1; render_phase += 1;
match *render_phase() { match *render_phase() {
0 => render! { 0 => rsx! {
nav_bar {} nav_bar {}
dash_board {} dash_board {}
}, },
1 => render! { 1 => rsx! {
nav_bar {} nav_bar {}
dash_results {} dash_results {}
}, },
2 => render! { 2 => rsx! {
nav_bar {} nav_bar {}
dash_board {} dash_board {}
}, },
3 => render! { 3 => rsx! {
nav_bar {} nav_bar {}
dash_results {} dash_results {}
}, },
4 => render! { 4 => rsx! {
nav_bar {} nav_bar {}
dash_board {} dash_board {}
}, },
_ => render!("blah"), _ => rsx!("blah"),
} }
} }
fn nav_bar() -> Element { fn nav_bar() -> Element {
render! { rsx! {
h1 { "NavBar", {(0..3).map(|_| render!(nav_link {}))} } h1 { "NavBar", {(0..3).map(|_| rsx!(nav_link {}))} }
} }
} }
fn nav_link() -> Element { fn nav_link() -> Element {
render!( h1 { "nav_link" } ) rsx!( h1 { "nav_link" } )
} }
fn dash_board() -> Element { fn dash_board() -> Element {
render!( div { "dashboard" } ) rsx!( div { "dashboard" } )
} }
fn dash_results() -> Element { fn dash_results() -> Element {
render!( div { "results" } ) rsx!( div { "results" } )
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
+3 -3
View File
@@ -6,7 +6,7 @@ use dioxus_core::{ElementId, NoOpMutations};
fn text_diff() { fn text_diff() {
fn app() -> Element { fn app() -> Element {
let gen = generation(); let gen = generation();
render!( h1 { "hello {gen}" } ) rsx!( h1 { "hello {gen}" } )
} }
let mut vdom = VirtualDom::new(app); let mut vdom = VirtualDom::new(app);
@@ -37,8 +37,8 @@ fn element_swap() {
let gen = generation(); let gen = generation();
match gen % 2 { match gen % 2 {
0 => render!( h1 { "hello 1" } ), 0 => rsx!( h1 { "hello 1" } ),
1 => render!( h2 { "hello 2" } ), 1 => rsx!( h2 { "hello 2" } ),
_ => unreachable!(), _ => unreachable!(),
} }
} }
+12 -12
View File
@@ -17,7 +17,7 @@ fn keyed_diffing_out_of_order() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
{ {
@@ -59,7 +59,7 @@ fn keyed_diffing_out_of_order_adds() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -85,7 +85,7 @@ fn keyed_diffing_out_of_order_adds_3() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -111,7 +111,7 @@ fn keyed_diffing_out_of_order_adds_4() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -137,7 +137,7 @@ fn keyed_diffing_out_of_order_adds_5() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -162,7 +162,7 @@ fn keyed_diffing_additions() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -187,7 +187,7 @@ fn keyed_diffing_additions_and_moves_on_ends() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -216,7 +216,7 @@ fn keyed_diffing_additions_and_moves_in_middle() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -250,7 +250,7 @@ fn controlled_keyed_diffing_out_of_order() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -284,7 +284,7 @@ fn controlled_keyed_diffing_out_of_order_max_test() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -313,7 +313,7 @@ fn remove_list() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
@@ -338,7 +338,7 @@ fn no_common_keys() {
_ => unreachable!(), _ => unreachable!(),
}; };
render!({ order.iter().map(|i| render!(div { key: "{i}" })) }) rsx!({ order.iter().map(|i| rsx!(div { key: "{i}" })) })
}); });
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);
+7 -7
View File
@@ -7,7 +7,7 @@ fn list_creates_one_by_one() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
let gen = generation(); let gen = generation();
render! { rsx! {
div { div {
for i in 0..gen { for i in 0..gen {
div { "{i}" } div { "{i}" }
@@ -76,7 +76,7 @@ fn removes_one_by_one() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
let gen = 3 - generation() % 4; let gen = 3 - generation() % 4;
render! { rsx! {
div { div {
for i in 0..gen { for i in 0..gen {
div { "{i}" } div { "{i}" }
@@ -151,7 +151,7 @@ fn removes_one_by_one() {
#[test] #[test]
fn list_shrink_multiroot() { fn list_shrink_multiroot() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
div { div {
for i in 0..generation() { for i in 0..generation() {
div { "{i}" } div { "{i}" }
@@ -212,7 +212,7 @@ fn removes_one_by_one_multiroot() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
let gen = 3 - generation() % 4; let gen = 3 - generation() % 4;
render! { rsx! {
div { div {
{(0..gen).map(|i| rsx! { {(0..gen).map(|i| rsx! {
div { "{i}" } div { "{i}" }
@@ -275,7 +275,7 @@ fn removes_one_by_one_multiroot() {
#[test] #[test]
fn two_equal_fragments_are_equal_static() { fn two_equal_fragments_are_equal_static() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
for _ in 0..5 { for _ in 0..5 {
div { "hello" } div { "hello" }
} }
@@ -289,7 +289,7 @@ fn two_equal_fragments_are_equal_static() {
#[test] #[test]
fn two_equal_fragments_are_equal() { fn two_equal_fragments_are_equal() {
let mut dom = VirtualDom::new(|| { let mut dom = VirtualDom::new(|| {
render! { rsx! {
for i in 0..5 { for i in 0..5 {
div { "hello {i}" } div { "hello {i}" }
} }
@@ -310,7 +310,7 @@ fn remove_many() {
_ => unreachable!(), _ => unreachable!(),
}; };
render! { rsx! {
for i in 0..num { for i in 0..num {
div { "hello {i}" } div { "hello {i}" }
} }
+2 -2
View File
@@ -9,7 +9,7 @@ fn catches_panic() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
h1 { "Title" } h1 { "Title" }
@@ -28,5 +28,5 @@ fn ThrowChild() -> Element {
let _g: i32 = "123123".parse().throw()?; let _g: i32 = "123123".parse().throw()?;
render! { div {} } rsx! { div {} }
} }
+3 -3
View File
@@ -52,14 +52,14 @@ fn events_propagate() {
} }
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { onclick: move |_| { div { onclick: move |_| {
println!("top clicked"); println!("top clicked");
*CLICKS.lock().unwrap() += 1; *CLICKS.lock().unwrap() += 1;
}, },
{vec![ {vec![
render! { rsx! {
problematic_child {} problematic_child {}
} }
].into_iter()} ].into_iter()}
@@ -68,7 +68,7 @@ fn app() -> Element {
} }
fn problematic_child() -> Element { fn problematic_child() -> Element {
render! { rsx! {
button { onclick: move |evt| { button { onclick: move |evt| {
println!("bottom clicked"); println!("bottom clicked");
let mut clicks = CLICKS.lock().unwrap(); let mut clicks = CLICKS.lock().unwrap();
+1 -1
View File
@@ -5,7 +5,7 @@ fn basic_syntax_is_a_template() -> Element {
let asd = 123; let asd = 123;
let var = 123; let var = 123;
render! { rsx! {
div { key: "12345", class: "asd", class: "{asd}", class: if true { div { key: "12345", class: "asd", class: "{asd}", class: if true {
"{asd}" "{asd}"
}, class: if false { }, class: if false {
+2 -2
View File
@@ -19,7 +19,7 @@ fn manual_diffing() {
fn app(cx: AppProps) -> Element { fn app(cx: AppProps) -> Element {
let val = cx.value.lock().unwrap(); let val = cx.value.lock().unwrap();
render! { div { "{val}" } } rsx! { div { "{val}" } }
}; };
let value = Arc::new(Mutex::new("Hello")); let value = Arc::new(Mutex::new("Hello"));
@@ -46,7 +46,7 @@ fn events_generate() {
let mut count = use_signal(|| 0); let mut count = use_signal(|| 0);
match *count() { match *count() {
0 => render! { 0 => rsx! {
div { onclick: move |_| count += 1, div { onclick: move |_| count += 1,
div { "nested" } div { "nested" }
"Click me!" "Click me!"
+2 -2
View File
@@ -27,7 +27,7 @@ fn app() -> Element {
let mut idx = use_signal(|| 0); let mut idx = use_signal(|| 0);
let onhover = |_| println!("go!"); let onhover = |_| println!("go!");
render! { rsx! {
div { div {
button { button {
onclick: move |_| { onclick: move |_| {
@@ -48,5 +48,5 @@ fn app() -> Element {
#[component] #[component]
fn ChildExample(i: i32, onhover: EventHandler<MouseEvent>) -> Element { fn ChildExample(i: i32, onhover: EventHandler<MouseEvent>) -> Element {
render! { li { onmouseover: move |e| onhover.call(e), "{i}" } } rsx! { li { onmouseover: move |e| onhover.call(e), "{i}" } }
} }
+11 -11
View File
@@ -3,7 +3,7 @@ use dioxus::prelude::*;
#[test] #[test]
fn app_drops() { fn app_drops() {
fn app() -> Element { fn app() -> Element {
render! { div {} } rsx! { div {} }
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -21,7 +21,7 @@ fn hooks_drop() {
use_hook(|| String::from("asd")); use_hook(|| String::from("asd"));
use_hook(|| String::from("asd")); use_hook(|| String::from("asd"));
render! { div {} } rsx! { div {} }
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -36,7 +36,7 @@ fn contexts_drop() {
fn app() -> Element { fn app() -> Element {
provide_context(String::from("asd")); provide_context(String::from("asd"));
render! { rsx! {
div { ChildComp {} } div { ChildComp {} }
} }
} }
@@ -44,7 +44,7 @@ fn contexts_drop() {
fn ChildComp() -> Element { fn ChildComp() -> Element {
let el = consume_context::<String>().unwrap(); let el = consume_context::<String>().unwrap();
render! { div { "hello {el}" } } rsx! { div { "hello {el}" } }
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -61,7 +61,7 @@ fn tasks_drop() {
// tokio::time::sleep(std::time::Duration::from_millis(100000)).await; // tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
}); });
render! { div {} } rsx! { div {} }
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -77,7 +77,7 @@ fn root_props_drop() {
struct RootProps(String); struct RootProps(String);
let mut dom = VirtualDom::new_with_props( let mut dom = VirtualDom::new_with_props(
|cx| render!( div { "{cx.0}" } ), |cx| rsx!( div { "{cx.0}" } ),
RootProps("asdasd".to_string()), RootProps("asdasd".to_string()),
); );
@@ -89,11 +89,11 @@ fn root_props_drop() {
#[test] #[test]
fn diffing_drops_old() { fn diffing_drops_old() {
fn app() -> Element { fn app() -> Element {
render! { rsx! {
div { div {
match generation() % 2 { match generation() % 2 {
0 => render!( ChildComp1 { name: "asdasd".to_string() }), 0 => rsx!( ChildComp1 { name: "asdasd".to_string() }),
1 => render!( ChildComp2 { name: "asdasd".to_string() }), 1 => rsx!( ChildComp2 { name: "asdasd".to_string() }),
_ => todo!() _ => todo!()
} }
} }
@@ -102,12 +102,12 @@ fn diffing_drops_old() {
#[component] #[component]
fn ChildComp1(name: String) -> Element { fn ChildComp1(name: String) -> Element {
render! {"Hello {name}"} rsx! {"Hello {name}"}
} }
#[component] #[component]
fn ChildComp2(name: String) -> Element { fn ChildComp2(name: String) -> Element {
render! {"Goodbye {name}"} rsx! {"Goodbye {name}"}
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
+9 -9
View File
@@ -16,14 +16,14 @@ fn test_memory_leak() {
spawn(async {}); spawn(async {});
if val == 2 || val == 4 { if val == 2 || val == 4 {
return render!({}); return rsx!({});
} }
let mut name = use_hook(|| String::from("numbers: ")); let mut name = use_hook(|| String::from("numbers: "));
name.push_str("123 "); name.push_str("123 ");
render!( rsx!(
div { "Hello, world!" } div { "Hello, world!" }
Child {} Child {}
Child {} Child {}
@@ -45,7 +45,7 @@ fn test_memory_leak() {
} }
fn BorrowedChild(cx: BorrowedProps) -> Element { fn BorrowedChild(cx: BorrowedProps) -> Element {
render! { rsx! {
div { div {
"goodbye {cx.name}" "goodbye {cx.name}"
Child {} Child {}
@@ -55,7 +55,7 @@ fn test_memory_leak() {
} }
fn Child() -> Element { fn Child() -> Element {
render!( div { "goodbye world" } ) rsx!( div { "goodbye world" } )
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -79,7 +79,7 @@ fn memo_works_properly() {
let name = use_hook(|| String::from("asd")); let name = use_hook(|| String::from("asd"));
render!( rsx!(
div { "Hello, world! {name}" } div { "Hello, world! {name}" }
Child { na: "asdfg".to_string() } Child { na: "asdfg".to_string() }
) )
@@ -91,7 +91,7 @@ fn memo_works_properly() {
} }
fn Child(cx: ChildProps) -> Element { fn Child(cx: ChildProps) -> Element {
render!( div { "goodbye world" } ) rsx!( div { "goodbye world" } )
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
@@ -119,11 +119,11 @@ fn free_works_on_root_hooks() {
fn app(cx: AppProps) -> Element { fn app(cx: AppProps) -> Element {
let name: AppProps = use_hook(|| cx.clone()); let name: AppProps = use_hook(|| cx.clone());
render!(child_component { inner: name.inner.clone() }) rsx!(child_component { inner: name.inner.clone() })
} }
fn child_component(props: AppProps) -> Element { fn child_component(props: AppProps) -> Element {
render!( div { "{props.inner}" } ) rsx!( div { "{props.inner}" } )
} }
let ptr = Rc::new("asdasd".to_string()); let ptr = Rc::new("asdasd".to_string());
@@ -176,7 +176,7 @@ fn supports_async() {
let mid = colors[1]; let mid = colors[1];
let small = colors[2]; let small = colors[2];
render! { rsx! {
div { background: "{big}", height: "stretch", width: "stretch", padding: "50", div { background: "{big}", height: "stretch", width: "stretch", padding: "50",
label { "hello" } label { "hello" }
div { background: "{mid}", height: "auto", width: "stretch", padding: "{padding}", div { background: "{mid}", height: "auto", width: "stretch", padding: "{padding}",
+1 -1
View File
@@ -5,7 +5,7 @@ use dioxus::prelude::*;
/// Ensure no issues with not calling rebuild_to_vec /// Ensure no issues with not calling rebuild_to_vec
#[test] #[test]
fn root_node_isnt_null() { fn root_node_isnt_null() {
let dom = VirtualDom::new(|| render!("Hello world!")); let dom = VirtualDom::new(|| rsx!("Hello world!"));
let scope = dom.base_scope(); let scope = dom.base_scope();
+2 -2
View File
@@ -20,7 +20,7 @@ fn suspense_resolves() {
} }
fn app() -> Element { fn app() -> Element {
render!( rsx!(
div { div {
"Waiting for... " "Waiting for... "
suspended_child {} suspended_child {}
@@ -38,5 +38,5 @@ fn suspended_child() -> Element {
suspend()?; suspend()?;
} }
render!("child") rsx!("child")
} }
+1 -1
View File
@@ -25,7 +25,7 @@ async fn it_works() {
}); });
}); });
render!({ () }) rsx!({ () })
} }
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
+1 -1
View File
@@ -209,7 +209,7 @@ fn app() -> Element {
desktop_context.close(); desktop_context.close();
} }
render! { rsx! {
div { div {
div { div {
width: "100px", width: "100px",
+1 -1
View File
@@ -75,7 +75,7 @@ fn check_html_renders() -> Element {
} }
}; };
render! { rsx! {
div { div {
id: "main_div", id: "main_div",
div { div {
+2 -2
View File
@@ -103,7 +103,7 @@ fn Example() -> Element {
// both of these are equivalent // both of these are equivalent
rsx!("hello world")) rsx!("hello world"))
render!("hello world!") rsx!("hello world!")
} }
``` ```
@@ -246,7 +246,7 @@ use hooks to define the state and modify it from within listeners.
fn App() -> Element { fn App() -> Element {
let name = use_signal(|| "world"); let name = use_signal(|| "world");
render!("hello {name}!") rsx!("hello {name}!")
} }
``` ```
+1 -1
View File
@@ -116,7 +116,7 @@ fn Grid(cx: Scope<GridProps>) -> Element {
} }
} }
render! { rsx! {
div{ div{
width: "100%", width: "100%",
height: "100%", height: "100%",
Loaded 100 of 148 files, more files were not shown because too many files have changed in this diff. Show more