Less clumsy configuration for desktop and mobile (#553)

* chore: dont use prebuilt builder pattern for configuring desktop

* chore: use regular config pattern for web

* Chore: update docs too

* chore: clean up some warnings
This commit is contained in:
Jon Kelley authored and GitHub committed 2022-09-13 16:22:27 -07:00
1 parent 41b450eedf
commit 540e785d8b
28 files changed
+172 -156

No files matched your search

+8 -12
View File
@@ -60,10 +60,10 @@ struct OptionalProps<'a> {
}
fn Title<'a>(cx: Scope<'a, OptionalProps>) -> Element<'a> {
return cx.render(rsx!(h1{
cx.render(rsx!(h1{
"{cx.props.title}: ",
[cx.props.subtitle.unwrap_or("No subtitle provided")],
}));
cx.props.subtitle.unwrap_or("No subtitle provided"),
}))
}
// ANCHOR_END: OptionalProps
@@ -76,10 +76,10 @@ struct ExplicitOptionProps<'a> {
}
fn ExplicitOption<'a>(cx: Scope<'a, ExplicitOptionProps>) -> Element<'a> {
return cx.render(rsx!(h1{
cx.render(rsx!(h1 {
"{cx.props.title}: ",
[cx.props.subtitle.unwrap_or("No subtitle provided")],
}));
cx.props.subtitle.unwrap_or("No subtitle provided"),
}))
}
// ANCHOR_END: ExplicitOption
@@ -92,9 +92,7 @@ struct DefaultProps {
}
fn DefaultComponent(cx: Scope<DefaultProps>) -> Element {
return cx.render(rsx!(h1{
"{cx.props.number}",
}));
cx.render(rsx!(h1 { "{cx.props.number}" }))
}
// ANCHOR_END: DefaultComponent
@@ -106,8 +104,6 @@ struct IntoProps {
}
fn IntoComponent(cx: Scope<IntoProps>) -> Element {
return cx.render(rsx!(h1{
"{cx.props.string}",
}));
cx.render(rsx!(h1 { "{cx.props.string}" }))
}
// ANCHOR_END: IntoComponent
+1 -1
View File
@@ -55,7 +55,7 @@ fn App(cx: Scope) -> Element {
}
// ✅ Instead, use a hashmap with use_ref
let selection_map = use_ref(&cx, || HashMap::<&str, bool>::new());
let selection_map = use_ref(&cx, HashMap::<&str, bool>::new);
for name in &names {
let is_selected = selection_map.read()[name];
+1 -1
View File
@@ -8,6 +8,6 @@ struct AppSettings {}
// ANCHOR: wrap_context
fn use_settings(cx: &ScopeState) -> UseSharedState<AppSettings> {
use_context::<AppSettings>(&cx).expect("App settings not provided")
use_context::<AppSettings>(cx).expect("App settings not provided")
}
// ANCHOR_END: wrap_context
+1 -1
View File
@@ -7,7 +7,7 @@ fn main() {
// ANCHOR: component
fn App(cx: Scope) -> Element {
let list = use_ref(&cx, || Vec::new());
let list = use_ref(&cx, Vec::new);
let list_formatted = format!("{:?}", *list.read());
cx.render(rsx!(
+1 -1
View File
@@ -37,7 +37,7 @@ pub fn App(cx: Scope) -> Element {
pub fn use_is_dark_mode(cx: &ScopeState) -> bool {
// ANCHOR: use_context
let dark_mode_context = use_context::<DarkMode>(&cx);
let dark_mode_context = use_context::<DarkMode>(cx);
// ANCHOR_END: use_context
dark_mode_context
+2 -2
View File
@@ -14,9 +14,9 @@ struct Comment {
pub fn App(cx: Scope) -> Element {
// ANCHOR: render_list
let comment_field = use_state(&cx, || String::new());
let comment_field = use_state(&cx, String::new);
let mut next_id = use_state(&cx, || 0);
let comments = use_ref(&cx, || Vec::<Comment>::new());
let comments = use_ref(&cx, Vec::<Comment>::new);
let comments_lock = comments.read();
let comments_rendered = comments_lock.iter().map(|comment| {