Remove lower case components that use the paran syntax (#551)
* chore: remove lowercase components * chore: add docs are lowercase components * docs: also add docs around lowercase components in current scope
This commit is contained in:
1 parent
d4d5d2733e
commit
38e8745db9
5 files changed
+56
-46
No files matched your search
+21
-8
@@ -184,11 +184,8 @@ fn app(cx: Scope) -> Element {
|
|||||||
// Can take children too!
|
// Can take children too!
|
||||||
Taller { a: "asd", div {"hello world!"} }
|
Taller { a: "asd", div {"hello world!"} }
|
||||||
|
|
||||||
// Components can be used with the `call` syntax
|
|
||||||
// This component's props are defined *inline* with the `inline_props` macro
|
// This component's props are defined *inline* with the `inline_props` macro
|
||||||
with_inline(
|
WithInline { text: "using functionc all syntax" }
|
||||||
text: "using functionc all syntax"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Components can be geneirc too
|
// Components can be geneirc too
|
||||||
// This component takes i32 type to give you typed input
|
// This component takes i32 type to give you typed input
|
||||||
@@ -196,8 +193,14 @@ fn app(cx: Scope) -> Element {
|
|||||||
// Type inference can be used too
|
// Type inference can be used too
|
||||||
TypedInput { initial: 10.0 }
|
TypedInput { initial: 10.0 }
|
||||||
// geneircs with the `inline_props` macro
|
// geneircs with the `inline_props` macro
|
||||||
label(text: "hello geneirc world!")
|
Label { text: "hello geneirc world!" }
|
||||||
label(text: 99.9)
|
Label { text: 99.9 }
|
||||||
|
|
||||||
|
// Lowercase components work too, as long as they are access using a path
|
||||||
|
baller::lowercase_component {}
|
||||||
|
|
||||||
|
// For in-scope lowercase components, use the `self` keyword
|
||||||
|
self::lowercase_helper {}
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
// Single values must be wrapped in braces or `Some` to satisfy `IntoIterator`
|
// 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> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lowercase_helper(cx: Scope) -> Element {
|
||||||
|
cx.render(rsx! {
|
||||||
|
"asd"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
mod baller {
|
mod baller {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[derive(Props, PartialEq)]
|
#[derive(Props, PartialEq)]
|
||||||
@@ -222,6 +231,10 @@ mod baller {
|
|||||||
pub fn Baller(_: Scope<BallerProps>) -> Element {
|
pub fn Baller(_: Scope<BallerProps>) -> Element {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lowercase_component(cx: Scope) -> Element {
|
||||||
|
cx.render(rsx! { "look ma, no uppercase" })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Props)]
|
#[derive(Props)]
|
||||||
@@ -255,7 +268,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline_props]
|
#[inline_props]
|
||||||
fn with_inline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
|
fn WithInline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
p { "{text}" }
|
p { "{text}" }
|
||||||
})
|
})
|
||||||
@@ -263,7 +276,7 @@ fn with_inline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
|
|||||||
|
|
||||||
// generic component with inline_props too
|
// generic component with inline_props too
|
||||||
#[inline_props]
|
#[inline_props]
|
||||||
fn label<T>(cx: Scope, text: T) -> Element
|
fn Label<T>(cx: Scope, text: T) -> Element
|
||||||
where
|
where
|
||||||
T: Display,
|
T: Display,
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -73,7 +73,7 @@ pub fn app(cx: Scope<()>) -> Element {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ul { class: "todo-list",
|
ul { class: "todo-list",
|
||||||
filtered_todos.iter().map(|id| rsx!(todo_entry( key: "{id}", id: *id, todos: todos )))
|
filtered_todos.iter().map(|id| rsx!(TodoEntry { key: "{id}", id: *id, todos: todos }))
|
||||||
}
|
}
|
||||||
(!todos.is_empty()).then(|| rsx!(
|
(!todos.is_empty()).then(|| rsx!(
|
||||||
footer { class: "footer",
|
footer { class: "footer",
|
||||||
@@ -111,7 +111,7 @@ pub struct TodoEntryProps<'a> {
|
|||||||
id: u32,
|
id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn todo_entry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
||||||
let is_editing = use_state(&cx, || false);
|
let is_editing = use_state(&cx, || false);
|
||||||
|
|
||||||
let todos = cx.props.todos.get();
|
let todos = cx.props.todos.get();
|
||||||
|
|||||||
@@ -34,17 +34,17 @@ fn test_memory_leak() {
|
|||||||
|
|
||||||
cx.render(rsx!(
|
cx.render(rsx!(
|
||||||
div { "Hello, world!" }
|
div { "Hello, world!" }
|
||||||
child()
|
Child {}
|
||||||
child()
|
Child {}
|
||||||
child()
|
Child {}
|
||||||
child()
|
Child {}
|
||||||
child()
|
Child {}
|
||||||
child()
|
Child {}
|
||||||
borrowed_child(na: name)
|
BorrowedChild { na: name }
|
||||||
borrowed_child(na: name)
|
BorrowedChild { na: name }
|
||||||
borrowed_child(na: name)
|
BorrowedChild { na: name }
|
||||||
borrowed_child(na: name)
|
BorrowedChild { na: name }
|
||||||
borrowed_child(na: name)
|
BorrowedChild { na: name }
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,15 +53,15 @@ fn test_memory_leak() {
|
|||||||
na: &'a str,
|
na: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrowed_child<'a>(cx: Scope<'a, BorrowedProps<'a>>) -> Element {
|
fn BorrowedChild<'a>(cx: Scope<'a, BorrowedProps<'a>>) -> Element {
|
||||||
rsx!(cx, div {
|
rsx!(cx, div {
|
||||||
"goodbye {cx.props.na}"
|
"goodbye {cx.props.na}"
|
||||||
child()
|
Child {}
|
||||||
child()
|
Child {}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child(cx: Scope) -> Element {
|
fn Child(cx: Scope) -> Element {
|
||||||
rsx!(cx, div { "goodbye world" })
|
rsx!(cx, div { "goodbye world" })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ fn memo_works_properly() {
|
|||||||
|
|
||||||
cx.render(rsx!(
|
cx.render(rsx!(
|
||||||
div { "Hello, world! {name}" }
|
div { "Hello, world! {name}" }
|
||||||
child(na: "asdfg".to_string() )
|
Child { na: "asdfg".to_string() }
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ fn memo_works_properly() {
|
|||||||
na: String,
|
na: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child(cx: Scope<ChildProps>) -> Element {
|
fn Child(cx: Scope<ChildProps>) -> Element {
|
||||||
rsx!(cx, div { "goodbye world" })
|
rsx!(cx, div { "goodbye world" })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,10 +120,10 @@ fn memo_works_properly() {
|
|||||||
fn free_works_on_root_props() {
|
fn free_works_on_root_props() {
|
||||||
fn app(cx: Scope<Custom>) -> Element {
|
fn app(cx: Scope<Custom>) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
child(a: "alpha")
|
Child { a: "alpha"}
|
||||||
child(a: "beta")
|
Child { a: "beta"}
|
||||||
child(a: "gamma")
|
Child { a: "gamma"}
|
||||||
child(a: "delta")
|
Child { a: "delta"}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ fn free_works_on_root_props() {
|
|||||||
a: &'static str,
|
a: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child(cx: Scope<ChildProps>) -> Element {
|
fn Child(cx: Scope<ChildProps>) -> Element {
|
||||||
rsx!(cx, "child {cx.props.a}")
|
rsx!(cx, "child {cx.props.a}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ fn free_works_on_root_props() {
|
|||||||
fn free_works_on_borrowed() {
|
fn free_works_on_borrowed() {
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
child(a: "alpha", b: "asd".to_string())
|
Child { a: "alpha", b: "asd".to_string() }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
#[derive(Props)]
|
#[derive(Props)]
|
||||||
@@ -163,7 +163,7 @@ fn free_works_on_borrowed() {
|
|||||||
b: String,
|
b: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
||||||
dbg!("rendering child");
|
dbg!("rendering child");
|
||||||
rsx!(cx, "child {cx.props.a}, {cx.props.b}")
|
rsx!(cx, "child {cx.props.a}, {cx.props.b}")
|
||||||
}
|
}
|
||||||
@@ -208,9 +208,9 @@ fn old_props_arent_stale() {
|
|||||||
*cnt += 1;
|
*cnt += 1;
|
||||||
|
|
||||||
if *cnt == 1 {
|
if *cnt == 1 {
|
||||||
rsx!(cx, div { child(a: "abcdef".to_string()) })
|
rsx!(cx, div { Child { a: "abcdef".to_string() } })
|
||||||
} else {
|
} else {
|
||||||
rsx!(cx, div { child(a: "abcdef".to_string()) })
|
rsx!(cx, div { Child { a: "abcdef".to_string() } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ fn old_props_arent_stale() {
|
|||||||
struct ChildProps {
|
struct ChildProps {
|
||||||
a: String,
|
a: String,
|
||||||
}
|
}
|
||||||
fn child(cx: Scope<ChildProps>) -> Element {
|
fn Child(cx: Scope<ChildProps>) -> Element {
|
||||||
dbg!("rendering child", &cx.props.a);
|
dbg!("rendering child", &cx.props.a);
|
||||||
rsx!(cx, div { "child {cx.props.a}" })
|
rsx!(cx, div { "child {cx.props.a}" })
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ fn old_props_arent_stale() {
|
|||||||
fn basic() {
|
fn basic() {
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
rsx!(cx, div {
|
rsx!(cx, div {
|
||||||
child(a: "abcdef".to_string())
|
Child { a: "abcdef".to_string() }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ fn basic() {
|
|||||||
a: String,
|
a: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child(cx: Scope<ChildProps>) -> Element {
|
fn Child(cx: Scope<ChildProps>) -> Element {
|
||||||
dbg!("rendering child", &cx.props.a);
|
dbg!("rendering child", &cx.props.a);
|
||||||
rsx!(cx, div { "child {cx.props.a}" })
|
rsx!(cx, div { "child {cx.props.a}" })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,17 +74,14 @@ impl Parse for BodyNode {
|
|||||||
//
|
//
|
||||||
// example
|
// example
|
||||||
// Div {}
|
// Div {}
|
||||||
// Div ()
|
|
||||||
// ::Div {}
|
// ::Div {}
|
||||||
// crate::Div {}
|
// crate::Div {}
|
||||||
// component()
|
// component {} <-- already handled by elements
|
||||||
// ::component {}
|
// ::component {}
|
||||||
// ::component ()
|
|
||||||
// crate::component{}
|
// crate::component{}
|
||||||
// crate::component()
|
|
||||||
// Input::<InputProps<'_, i32> {}
|
// Input::<InputProps<'_, i32> {}
|
||||||
// crate::Input::<InputProps<'_, i32> {}
|
// crate::Input::<InputProps<'_, i32> {}
|
||||||
if body_stream.peek(token::Brace) || body_stream.peek(token::Paren) {
|
if body_stream.peek(token::Brace) {
|
||||||
Component::validate_component_path(&path)?;
|
Component::validate_component_path(&path)?;
|
||||||
|
|
||||||
return Ok(BodyNode::Component(stream.parse()?));
|
return Ok(BodyNode::Component(stream.parse()?));
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
h2 { "thing 2"}
|
h2 { "thing 2"}
|
||||||
"asd"
|
"asd"
|
||||||
"asd"
|
"asd"
|
||||||
bapp()
|
Bapp {}
|
||||||
}
|
}
|
||||||
(0..10).map(|f| rsx!{
|
(0..10).map(|f| rsx!{
|
||||||
div {
|
div {
|
||||||
@@ -23,7 +23,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bapp(cx: Scope) -> Element {
|
fn Bapp(cx: Scope) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div {
|
div {
|
||||||
h1 { "thing 1" }
|
h1 { "thing 1" }
|
||||||
|
|||||||
Reference in new issue
Block a user