Skip to content

Commit 41b450e

Browse files
authored
chore: remove unnecessary brackets from examples (DioxusLabs#552)
1 parent e4466fe commit 41b450e

11 files changed

+44
-52
lines changed

examples/calculator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ fn app(cx: Scope) -> Element {
5757
};
5858

5959
cx.render(rsx!(
60-
style { [include_str!("./assets/calculator.css")] }
60+
style { include_str!("./assets/calculator.css") }
6161
div { id: "wrapper",
6262
div { class: "app",
6363
div { class: "calculator",
6464
onkeydown: handle_key_down_event,
65-
div { class: "calculator-display", [val.to_string()] }
65+
div { class: "calculator-display", val.to_string() }
6666
div { class: "calculator-keypad",
6767
div { class: "input-keys",
6868
div { class: "function-keys",
@@ -74,7 +74,7 @@ fn app(cx: Scope) -> Element {
7474
val.set("0".into());
7575
}
7676
},
77-
[if val.is_empty() { "C" } else { "AC" }]
77+
if val.is_empty() { "C" } else { "AC" }
7878
}
7979
button {
8080
class: "calculator-key key-sign",

examples/disabled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn app(cx: Scope) -> Element {
1212
button {
1313
onclick: move |_| disabled.set(!disabled),
1414
"click to "
15-
[if disabled == true {"enable"} else {"disable"}]
15+
if disabled == true { "enable" } else { "disable" }
1616
" the lower button"
1717
}
1818

examples/file_explorer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ fn app(cx: Scope) -> Element {
1919

2020
rsx!(cx, div {
2121
link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet", }
22-
style { [include_str!("./assets/fileexplorer.css")] }
22+
style { include_str!("./assets/fileexplorer.css") }
2323
header {
2424
i { class: "material-icons icon-menu", "menu" }
25-
h1 { "Files: " [files.read().current()] }
25+
h1 { "Files: ", files.read().current() }
2626
span { }
2727
i { class: "material-icons", onclick: move |_| files.write().go_up(), "logout" }
2828
}

examples/inputs.rs

-7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ const FIELDS: &[(&str, &str)] = &[
3838
fn app(cx: Scope) -> Element {
3939
cx.render(rsx! {
4040
div { margin_left: "30px",
41-
42-
// radio group
43-
44-
45-
46-
4741
div {
4842
// handling inputs on divs will catch all input events below
4943
// so the value of our input event will be either huey, dewey, louie, or true/false (because of the checkboxe)
@@ -127,7 +121,6 @@ fn app(cx: Scope) -> Element {
127121
name: "{field}",
128122
r#type: "{field}",
129123
value: "{value}",
130-
// checked: "false",
131124
oninput: move |evt: FormEvent| {
132125
println!("{:?}", evt);
133126
},

examples/nested_listeners.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ fn app(cx: Scope) -> Element {
1515
div {
1616
onclick: move |_| println!("clicked! top"),
1717
"- div"
18-
1918
button {
2019
onclick: move |_| println!("clicked! bottom propoate"),
2120
"Propogate"

examples/pattern_model.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ fn app(cx: Scope) -> Element {
3636
let state = use_ref(&cx, Calculator::new);
3737

3838
cx.render(rsx! {
39-
style { [include_str!("./assets/calculator.css")] }
39+
style { include_str!("./assets/calculator.css") }
4040
div { id: "wrapper",
4141
div { class: "app",
4242
div { class: "calculator", onkeypress: move |evt| state.write().handle_keydown(evt),
43-
div { class: "calculator-display", [state.read().formatted_display()]}
43+
div { class: "calculator-display", state.read().formatted_display() }
4444
div { class: "calculator-keypad",
4545
div { class: "input-keys",
4646
div { class: "function-keys",
4747
CalculatorKey {
4848
name: "key-clear",
4949
onclick: move |_| state.write().clear_display(),
50-
[if state.read().display_value == "0" { "C" } else { "AC" }]
50+
if state.read().display_value == "0" { "C" } else { "AC" }
5151
}
5252
CalculatorKey {
5353
name: "key-sign",

examples/pattern_reducer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element {
2020
cx.render(rsx!(
2121
div {
2222
h1 {"Select an option"}
23-
h3 { "The radio is... " [state.is_playing()] "!" }
23+
h3 { "The radio is... ", state.is_playing(), "!" }
2424
button { onclick: move |_| state.make_mut().reduce(PlayerAction::Pause),
2525
"Pause"
2626
}

examples/rsx_compile_fail.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,19 @@ fn example(cx: Scope) -> Element {
3232

3333
cx.render(rsx!(
3434
div {
35-
div {
36-
id: "asd",
35+
div { id: "asd",
3736
"your neighborhood spiderman"
3837

3938
items.iter().cycle().take(5).map(|f| rsx!{
40-
div {
41-
"{f.a}"
42-
}
39+
div { "{f.a}" }
4340
})
4441

4542
things_list.iter().map(|f| rsx!{
46-
div {
47-
"{f.a}"
48-
"{f.b}"
49-
}
43+
div { "{f.a}" "{f.b}" }
5044
})
5145

52-
mything_read.as_ref().map(|f| rsx!{
53-
div {
54-
"{f}"
55-
}
46+
mything_read.as_ref().map(|f| rsx! {
47+
div { "{f}" }
5648
})
5749
}
5850
}

examples/rsx_usage.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(non_snake_case)]
2+
13
//! A tour of the rsx! macro
24
//! ------------------------
35
//!
@@ -42,10 +44,6 @@ fn main() {
4244
dioxus_desktop::launch(app);
4345
}
4446

45-
/// When trying to return "nothing" to Dioxus, you'll need to specify the type parameter or Rust will be sad.
46-
/// This type alias specifies the type for you so you don't need to write "None as Option<()>"
47-
const NONE_ELEMENT: Option<()> = None;
48-
4947
use core::{fmt, str::FromStr};
5048
use std::fmt::Display;
5149

@@ -63,7 +61,7 @@ fn app(cx: Scope) -> Element {
6361
h1 {"Some text"}
6462
h1 {"Some text with {formatting}"}
6563
h1 {"Formatting basic expressions {formatting_tuple.0} and {formatting_tuple.1}"}
66-
h1 {"Formatting without interpolation " [formatting_tuple.0] "and" [formatting_tuple.1] }
64+
h1 {"Formatting without interpolation " formatting_tuple.0 "and" formatting_tuple.1 }
6765
h2 {
6866
"Multiple"
6967
"Text"
@@ -131,13 +129,9 @@ fn app(cx: Scope) -> Element {
131129
None
132130
}
133131

134-
135132
// returning "None" without a diverging branch is a bit noisy... but rare in practice
136133
None as Option<()>,
137134

138-
// Use the Dioxus type-alias for less noise
139-
NONE_ELEMENT,
140-
141135
// can also just use empty fragments
142136
Fragment {}
143137

@@ -160,7 +154,7 @@ fn app(cx: Scope) -> Element {
160154
// Can accept any paths
161155
// Notice how you still get syntax highlighting and IDE support :)
162156
Baller {}
163-
baller::Baller { }
157+
baller::Baller {}
164158
crate::baller::Baller {}
165159

166160
// Can take properties
@@ -187,11 +181,13 @@ fn app(cx: Scope) -> Element {
187181
// This component's props are defined *inline* with the `inline_props` macro
188182
WithInline { text: "using functionc all syntax" }
189183

190-
// Components can be geneirc too
184+
// Components can be generic too
191185
// This component takes i32 type to give you typed input
192186
TypedInput::<TypedInputProps<i32>> {}
187+
193188
// Type inference can be used too
194189
TypedInput { initial: 10.0 }
190+
195191
// geneircs with the `inline_props` macro
196192
Label { text: "hello geneirc world!" }
197193
Label { text: 99.9 }
@@ -205,10 +201,23 @@ fn app(cx: Scope) -> Element {
205201
// helper functions
206202
// Anything that implements IntoVnode can be dropped directly into Rsx
207203
helper(&cx, "hello world!")
204+
205+
// Strings can be supplied directly
206+
String::from("Hello world!")
207+
208+
// So can format_args
209+
format_args!("Hello {}!", "world")
210+
211+
// Or we can shell out to a helper function
212+
format_dollars(10, 50)
208213
}
209214
})
210215
}
211216

217+
fn format_dollars(dollars: u32, cents: u32) -> String {
218+
format!("${}.{:02}", dollars, cents)
219+
}
220+
212221
fn helper<'a>(cx: &'a ScopeState, text: &str) -> Element<'a> {
213222
cx.render(rsx! {
214223
p { "{text}" }
@@ -223,7 +232,7 @@ fn lowercase_helper(cx: Scope) -> Element {
223232

224233
mod baller {
225234
use super::*;
226-
#[derive(Props, PartialEq)]
235+
#[derive(Props, PartialEq, Eq)]
227236
pub struct BallerProps {}
228237

229238
#[allow(non_snake_case)]
@@ -252,7 +261,7 @@ pub fn Taller<'a>(cx: Scope<'a, TallerProps<'a>>) -> Element {
252261
})
253262
}
254263

255-
#[derive(Props, PartialEq)]
264+
#[derive(Props, PartialEq, Eq)]
256265
pub struct TypedInputProps<T> {
257266
#[props(optional, default)]
258267
initial: Option<T>,

examples/todomvc.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
#![allow(non_snake_case)]
2+
13
use dioxus::prelude::*;
24
use dioxus_elements::input_data::keyboard_types::Key;
35

46
fn main() {
57
dioxus_desktop::launch(app);
68
}
79

8-
#[derive(PartialEq)]
10+
#[derive(Eq, PartialEq)]
911
pub enum FilterState {
1012
All,
1113
Active,
1214
Completed,
1315
}
1416

15-
#[derive(Debug, PartialEq, Clone)]
17+
#[derive(Debug, Eq, PartialEq, Clone)]
1618
pub struct TodoItem {
1719
pub id: u32,
1820
pub checked: bool,
@@ -46,7 +48,7 @@ pub fn app(cx: Scope<()>) -> Element {
4648

4749
cx.render(rsx!{
4850
section { class: "todoapp",
49-
style { [include_str!("./assets/todomvc.css")] }
51+
style { include_str!("./assets/todomvc.css") }
5052
div {
5153
header { class: "header",
5254
h1 {"todos"}
@@ -86,7 +88,7 @@ pub fn app(cx: Scope<()>) -> Element {
8688
li { class: "Active", a { onclick: move |_| filter.set(FilterState::Active), "Active" }}
8789
li { class: "Completed", a { onclick: move |_| filter.set(FilterState::Completed), "Completed" }}
8890
}
89-
(show_clear_completed).then(|| rsx!(
91+
show_clear_completed.then(|| rsx!(
9092
button {
9193
class: "clear-completed",
9294
onclick: move |_| todos.make_mut().retain(|_, todo| !todo.checked),
@@ -123,7 +125,6 @@ pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
123125
li {
124126
class: "{completed} {editing}",
125127
div { class: "view",
126-
127128
input {
128129
class: "toggle",
129130
r#type: "checkbox",

examples/window_event.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ fn app(cx: Scope) -> Element {
8484
button {
8585
class: "inline-flex items-center text-white bg-blue-500 border-0 py-1 px-3 hover:bg-green-700 rounded",
8686
onmousedown: |evt| evt.cancel_bubble(),
87-
onclick: move |_| {
88-
window.set_title("Dioxus Application");
89-
},
87+
onclick: move |_| window.set_title("Dioxus Application"),
9088
"Change Title"
9189
}
9290
}

0 commit comments

Comments
 (0)