Skip to content

Commit 38e8745

Browse files
authored
Remove lower case components that use the paran syntax (DioxusLabs#551)
* chore: remove lowercase components * chore: add docs are lowercase components * docs: also add docs around lowercase components in current scope
1 parent d4d5d27 commit 38e8745

File tree

5 files changed

+56
-46
lines changed

5 files changed

+56
-46
lines changed

examples/rsx_usage.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,23 @@ fn app(cx: Scope) -> Element {
184184
// Can take children too!
185185
Taller { a: "asd", div {"hello world!"} }
186186

187-
// Components can be used with the `call` syntax
188187
// This component's props are defined *inline* with the `inline_props` macro
189-
with_inline(
190-
text: "using functionc all syntax"
191-
)
188+
WithInline { text: "using functionc all syntax" }
192189

193190
// Components can be geneirc too
194191
// This component takes i32 type to give you typed input
195192
TypedInput::<TypedInputProps<i32>> {}
196193
// Type inference can be used too
197194
TypedInput { initial: 10.0 }
198195
// geneircs with the `inline_props` macro
199-
label(text: "hello geneirc world!")
200-
label(text: 99.9)
196+
Label { text: "hello geneirc world!" }
197+
Label { text: 99.9 }
198+
199+
// Lowercase components work too, as long as they are access using a path
200+
baller::lowercase_component {}
201+
202+
// For in-scope lowercase components, use the `self` keyword
203+
self::lowercase_helper {}
201204

202205
// helper functions
203206
// Single values must be wrapped in braces or `Some` to satisfy `IntoIterator`
@@ -212,6 +215,12 @@ fn helper<'a>(cx: &'a ScopeState, text: &str) -> Element<'a> {
212215
})
213216
}
214217

218+
fn lowercase_helper(cx: Scope) -> Element {
219+
cx.render(rsx! {
220+
"asd"
221+
})
222+
}
223+
215224
mod baller {
216225
use super::*;
217226
#[derive(Props, PartialEq)]
@@ -222,6 +231,10 @@ mod baller {
222231
pub fn Baller(_: Scope<BallerProps>) -> Element {
223232
todo!()
224233
}
234+
235+
pub fn lowercase_component(cx: Scope) -> Element {
236+
cx.render(rsx! { "look ma, no uppercase" })
237+
}
225238
}
226239

227240
#[derive(Props)]
@@ -255,15 +268,15 @@ where
255268
}
256269

257270
#[inline_props]
258-
fn with_inline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
271+
fn WithInline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
259272
cx.render(rsx! {
260273
p { "{text}" }
261274
})
262275
}
263276

264277
// generic component with inline_props too
265278
#[inline_props]
266-
fn label<T>(cx: Scope, text: T) -> Element
279+
fn Label<T>(cx: Scope, text: T) -> Element
267280
where
268281
T: Display,
269282
{

examples/todomvc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn app(cx: Scope<()>) -> Element {
7373
}
7474
}
7575
ul { class: "todo-list",
76-
filtered_todos.iter().map(|id| rsx!(todo_entry( key: "{id}", id: *id, todos: todos )))
76+
filtered_todos.iter().map(|id| rsx!(TodoEntry { key: "{id}", id: *id, todos: todos }))
7777
}
7878
(!todos.is_empty()).then(|| rsx!(
7979
footer { class: "footer",
@@ -111,7 +111,7 @@ pub struct TodoEntryProps<'a> {
111111
id: u32,
112112
}
113113

114-
pub fn todo_entry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
114+
pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
115115
let is_editing = use_state(&cx, || false);
116116

117117
let todos = cx.props.todos.get();

packages/dioxus/tests/miri_stress.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ fn test_memory_leak() {
3434

3535
cx.render(rsx!(
3636
div { "Hello, world!" }
37-
child()
38-
child()
39-
child()
40-
child()
41-
child()
42-
child()
43-
borrowed_child(na: name)
44-
borrowed_child(na: name)
45-
borrowed_child(na: name)
46-
borrowed_child(na: name)
47-
borrowed_child(na: name)
37+
Child {}
38+
Child {}
39+
Child {}
40+
Child {}
41+
Child {}
42+
Child {}
43+
BorrowedChild { na: name }
44+
BorrowedChild { na: name }
45+
BorrowedChild { na: name }
46+
BorrowedChild { na: name }
47+
BorrowedChild { na: name }
4848
))
4949
}
5050

@@ -53,15 +53,15 @@ fn test_memory_leak() {
5353
na: &'a str,
5454
}
5555

56-
fn borrowed_child<'a>(cx: Scope<'a, BorrowedProps<'a>>) -> Element {
56+
fn BorrowedChild<'a>(cx: Scope<'a, BorrowedProps<'a>>) -> Element {
5757
rsx!(cx, div {
5858
"goodbye {cx.props.na}"
59-
child()
60-
child()
59+
Child {}
60+
Child {}
6161
})
6262
}
6363

64-
fn child(cx: Scope) -> Element {
64+
fn Child(cx: Scope) -> Element {
6565
rsx!(cx, div { "goodbye world" })
6666
}
6767

@@ -91,7 +91,7 @@ fn memo_works_properly() {
9191

9292
cx.render(rsx!(
9393
div { "Hello, world! {name}" }
94-
child(na: "asdfg".to_string() )
94+
Child { na: "asdfg".to_string() }
9595
))
9696
}
9797

@@ -100,7 +100,7 @@ fn memo_works_properly() {
100100
na: String,
101101
}
102102

103-
fn child(cx: Scope<ChildProps>) -> Element {
103+
fn Child(cx: Scope<ChildProps>) -> Element {
104104
rsx!(cx, div { "goodbye world" })
105105
}
106106

@@ -120,10 +120,10 @@ fn memo_works_properly() {
120120
fn free_works_on_root_props() {
121121
fn app(cx: Scope<Custom>) -> Element {
122122
cx.render(rsx! {
123-
child(a: "alpha")
124-
child(a: "beta")
125-
child(a: "gamma")
126-
child(a: "delta")
123+
Child { a: "alpha"}
124+
Child { a: "beta"}
125+
Child { a: "gamma"}
126+
Child { a: "delta"}
127127
})
128128
}
129129

@@ -132,7 +132,7 @@ fn free_works_on_root_props() {
132132
a: &'static str,
133133
}
134134

135-
fn child(cx: Scope<ChildProps>) -> Element {
135+
fn Child(cx: Scope<ChildProps>) -> Element {
136136
rsx!(cx, "child {cx.props.a}")
137137
}
138138

@@ -154,7 +154,7 @@ fn free_works_on_root_props() {
154154
fn free_works_on_borrowed() {
155155
fn app(cx: Scope) -> Element {
156156
cx.render(rsx! {
157-
child(a: "alpha", b: "asd".to_string())
157+
Child { a: "alpha", b: "asd".to_string() }
158158
})
159159
}
160160
#[derive(Props)]
@@ -163,7 +163,7 @@ fn free_works_on_borrowed() {
163163
b: String,
164164
}
165165

166-
fn child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
166+
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
167167
dbg!("rendering child");
168168
rsx!(cx, "child {cx.props.a}, {cx.props.b}")
169169
}
@@ -208,17 +208,17 @@ fn old_props_arent_stale() {
208208
*cnt += 1;
209209

210210
if *cnt == 1 {
211-
rsx!(cx, div { child(a: "abcdef".to_string()) })
211+
rsx!(cx, div { Child { a: "abcdef".to_string() } })
212212
} else {
213-
rsx!(cx, div { child(a: "abcdef".to_string()) })
213+
rsx!(cx, div { Child { a: "abcdef".to_string() } })
214214
}
215215
}
216216

217217
#[derive(Props, PartialEq)]
218218
struct ChildProps {
219219
a: String,
220220
}
221-
fn child(cx: Scope<ChildProps>) -> Element {
221+
fn Child(cx: Scope<ChildProps>) -> Element {
222222
dbg!("rendering child", &cx.props.a);
223223
rsx!(cx, div { "child {cx.props.a}" })
224224
}
@@ -251,7 +251,7 @@ fn old_props_arent_stale() {
251251
fn basic() {
252252
fn app(cx: Scope) -> Element {
253253
rsx!(cx, div {
254-
child(a: "abcdef".to_string())
254+
Child { a: "abcdef".to_string() }
255255
})
256256
}
257257

@@ -260,7 +260,7 @@ fn basic() {
260260
a: String,
261261
}
262262

263-
fn child(cx: Scope<ChildProps>) -> Element {
263+
fn Child(cx: Scope<ChildProps>) -> Element {
264264
dbg!("rendering child", &cx.props.a);
265265
rsx!(cx, div { "child {cx.props.a}" })
266266
}

packages/rsx/src/node.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,14 @@ impl Parse for BodyNode {
7474
//
7575
// example
7676
// Div {}
77-
// Div ()
7877
// ::Div {}
7978
// crate::Div {}
80-
// component()
79+
// component {} <-- already handled by elements
8180
// ::component {}
82-
// ::component ()
8381
// crate::component{}
84-
// crate::component()
8582
// Input::<InputProps<'_, i32> {}
8683
// crate::Input::<InputProps<'_, i32> {}
87-
if body_stream.peek(token::Brace) || body_stream.peek(token::Paren) {
84+
if body_stream.peek(token::Brace) {
8885
Component::validate_component_path(&path)?;
8986

9087
return Ok(BodyNode::Component(stream.parse()?));

packages/web/examples/hydrate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn app(cx: Scope) -> Element {
1313
h2 { "thing 2"}
1414
"asd"
1515
"asd"
16-
bapp()
16+
Bapp {}
1717
}
1818
(0..10).map(|f| rsx!{
1919
div {
@@ -23,7 +23,7 @@ fn app(cx: Scope) -> Element {
2323
})
2424
}
2525

26-
fn bapp(cx: Scope) -> Element {
26+
fn Bapp(cx: Scope) -> Element {
2727
cx.render(rsx! {
2828
div {
2929
h1 { "thing 1" }

0 commit comments

Comments
 (0)