Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rstml 0.12 and braces in attribute values #2769

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions benchmarks/src/ssr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ fn leptos_ssr_bench(b: &mut Bencher) {
let (value, set_value) = create_signal(initial);
view! {
<div>
<button on:click=move |_| set_value.update(|value| *value -= 1)>"-1"</button>
<button on:click={move |_| {
set_value.update(|value| *value -= 1)
}}>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span>
<button on:click=move |_| set_value.update(|value| *value += 1)>"+1"</button>
<button on:click={move |_| {
set_value.update(|value| *value += 1)
}}>"+1"</button>
</div>
}
}

let rendered = view! {
let rendered = view! {
<main>
<h1>"Welcome to our benchmark page."</h1>
<p>"Here's some introductory text."</p>
<Counter initial=1/>
<Counter initial=2/>
<Counter initial=3/>
<Counter initial=1 />
<Counter initial=2 />
<Counter initial=3 />
</main>
}.into_view().render_to_string();

Expand All @@ -51,14 +55,14 @@ fn tachys_ssr_bench(b: &mut Bencher) {
let (value, set_value) = create_signal(initial);
view! {
<div>
<button on:click=move |_| set_value.update(|value| *value -= 1)>"-1"</button>
<button on:click={move |_| set_value.update(|value| *value -= 1)}>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span>
<button on:click=move |_| set_value.update(|value| *value += 1)>"+1"</button>
<button on:click={move |_| set_value.update(|value| *value += 1)}>"+1"</button>
</div>
}
}

let rendered = view! {
let rendered = view! {
<main>
<h1>"Welcome to our benchmark page."</h1>
<p>"Here's some introductory text."</p>
Expand Down
65 changes: 36 additions & 29 deletions benchmarks/src/todomvc/leptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn TodoMVC(todos: Todos) -> impl IntoView {
}
});

view! {
view! {
<main>
<section class="todoapp">
<header class="header">
Expand All @@ -176,59 +176,64 @@ pub fn TodoMVC(todos: Todos) -> impl IntoView {
class="new-todo"
placeholder="What needs to be done?"
autofocus=""
on:keydown=add_todo
on:keydown={add_todo}
/>
</header>
<section class="main" class:hidden=move || todos.with(|t| t.is_empty())>
<section class="main" class:hidden={move || todos.with(|t| t.is_empty())}>
<input
id="toggle-all"
class="toggle-all"
type="checkbox"
prop:checked=move || todos.with(|t| t.remaining() > 0)
on:input=move |_| set_todos.update(|t| t.toggle_all())
prop:checked={move || todos.with(|t| t.remaining() > 0)}
on:input={move |_| set_todos.update(|t| t.toggle_all())}
/>
<label for="toggle-all">"Mark all as complete"</label>
<ul class="todo-list">
<For
each=filtered_todos
key=|todo| todo.id
children=move |todo: Todo| {
view! { <Todo todo=todo.clone()/> }
}
each={filtered_todos}
key={|todo| todo.id}
children={move |todo: Todo| {
view! { <Todo todo={todo.clone()} /> }
}}
/>
</ul>
</section>
<footer class="footer" class:hidden=move || todos.with(|t| t.is_empty())>
<footer class="footer" class:hidden={move || todos.with(|t| t.is_empty())}>
<span class="todo-count">
<strong>{move || todos.with(|t| t.remaining().to_string())}</strong>
{move || if todos.with(|t| t.remaining()) == 1 { " item" } else { " items" }}
{move || {
if todos.with(|t| t.remaining()) == 1 { " item" } else { " items" }
}}
" left"
</span>
<ul class="filters">
<li>
<a
href="#/"
class="selected"
class:selected=move || mode() == Mode::All
class:selected={move || mode() == Mode::All}
>
"All"
</a>
</li>
<li>
<a href="#/active" class:selected=move || mode() == Mode::Active>
<a href="#/active" class:selected={move || mode() == Mode::Active}>
"Active"
</a>
</li>
<li>
<a href="#/completed" class:selected=move || mode() == Mode::Completed>
<a
href="#/completed"
class:selected={move || mode() == Mode::Completed}
>
"Completed"
</a>
</li>
</ul>
<button
class="clear-completed hidden"
class:hidden=move || todos.with(|t| t.completed() == 0)
on:click=move |_| set_todos.update(|t| t.clear_completed())
class:hidden={move || todos.with(|t| t.completed() == 0)}
on:click={move |_| set_todos.update(|t| t.clear_completed())}
>
"Clear completed"
</button>
Expand Down Expand Up @@ -259,33 +264,35 @@ pub fn Todo(todo: Todo) -> impl IntoView {
set_editing(false);
};

view! {
<li class="todo" class:editing=editing class:completed=move || (todo.completed)()>
view! {
<li class="todo" class:editing={editing} class:completed={move || (todo.completed)()}>
<div class="view">
<input class="toggle" type="checkbox" prop:checked=move || (todo.completed)()/>
<label on:dblclick=move |_| set_editing(true)>{move || todo.title.get()}</label>
<input class="toggle" type="checkbox" prop:checked={move || (todo.completed)()} />
<label on:dblclick={move |_| set_editing(true)}>{move || todo.title.get()}</label>
<button
class="destroy"
on:click=move |_| set_todos.update(|t| t.remove(todo.id))
on:click={move |_| set_todos.update(|t| t.remove(todo.id))}
></button>
</div>
{move || {
editing()
.then(|| {
view! {
view! {
<input
class="edit"
class:hidden=move || !(editing)()
prop:value=move || todo.title.get()
on:focusout=move |ev| save(&event_target_value(&ev))
on:keyup=move |ev| {
let key_code = ev.unchecked_ref::<web_sys::KeyboardEvent>().key_code();
class:hidden={move || !(editing)()}
prop:value={move || todo.title.get()}
on:focusout={move |ev| save(&event_target_value(&ev))}
on:keyup={move |ev| {
let key_code = ev
.unchecked_ref::<web_sys::KeyboardEvent>()
.key_code();
if key_code == ENTER_KEY {
save(&event_target_value(&ev));
} else if key_code == ESCAPE_KEY {
set_editing(false);
}
}
}}
/>
}
})
Expand Down
18 changes: 5 additions & 13 deletions benchmarks/src/todomvc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn leptos_todomvc_ssr(b: &mut Bencher) {
use crate::todomvc::leptos::*;

let html = ::leptos::ssr::render_to_string(|| {
view! { <TodoMVC todos=Todos::new()/> }
view! { <TodoMVC todos={Todos::new()} /> }
});
assert!(html.len() > 1);
});
Expand Down Expand Up @@ -45,10 +45,7 @@ fn sycamore_todomvc_ssr(b: &mut Bencher) {
b.iter(|| {
_ = create_scope(|cx| {
let rendered = render_to_string(|cx| {
view! {
cx,
App()
}
view! { cx, App() }
});

assert!(rendered.len() > 1);
Expand Down Expand Up @@ -77,9 +74,7 @@ fn leptos_todomvc_ssr_with_1000(b: &mut Bencher) {
use ::leptos::*;

let html = ::leptos::ssr::render_to_string(|| {
view! {
<TodoMVC todos=Todos::new_with_1000()/>
}
view! { <TodoMVC todos={Todos::new_with_1000()} /> }
});
assert!(html.len() > 1);
});
Expand Down Expand Up @@ -107,10 +102,7 @@ fn sycamore_todomvc_ssr_with_1000(b: &mut Bencher) {
b.iter(|| {
_ = create_scope(|cx| {
let rendered = render_to_string(|cx| {
view! {
cx,
AppWith1000()
}
view! { cx, AppWith1000() }
});

assert!(rendered.len() > 1);
Expand Down Expand Up @@ -140,7 +132,7 @@ fn tera_todomvc_ssr(b: &mut Bencher) {
use crate::todomvc::leptos::*;

let html = ::leptos::ssr::render_to_string(|| {
view! { <TodoMVC todos=Todos::new()/> }
view! { <TodoMVC todos={Todos::new()} /> }
});
assert!(html.len() > 1);
});
Expand Down
56 changes: 18 additions & 38 deletions benchmarks/src/todomvc/tachys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,58 +182,57 @@ pub fn TodoMVC(todos: Todos) -> impl Render<Dom> + RenderHtml<Dom> {
<section class="todoapp">
<header class="header">
<h1>"todos"</h1>
<input
class="new-todo"
placeholder="What needs to be done?"
autofocus
/>
<input class="new-todo" placeholder="What needs to be done?" autofocus />
</header>
<section class="main" class:hidden=move || todos.with(|t| t.is_empty())>
<section class="main" class:hidden={move || todos.with(|t| t.is_empty())}>
<input
id="toggle-all"
class="toggle-all"
r#type="checkbox"
//prop:checked=move || todos.with(|t| t.remaining() > 0)
on:input=move |_| set_todos.update(|t| t.toggle_all())
// prop:checked=move || todos.with(|t| t.remaining() > 0)
on:input={move |_| set_todos.update(|t| t.toggle_all())}
/>
<label r#for="toggle-all">"Mark all as complete"</label>
<ul class="todo-list">
{move || {
keyed(filtered_todos.get(), |todo| todo.id, Todo)
}}
{move || { keyed(filtered_todos.get(), |todo| todo.id, Todo) }}
</ul>
</section>
<footer class="footer" class:hidden=move || todos.with(|t| t.is_empty())>
<footer class="footer" class:hidden={move || todos.with(|t| t.is_empty())}>
<span class="todo-count">
<strong>{move || todos.with(|t| t.remaining().to_string())}</strong>
{move || if todos.with(|t| t.remaining()) == 1 { " item" } else { " items" }}
{move || {
if todos.with(|t| t.remaining()) == 1 { " item" } else { " items" }
}}
" left"
</span>
<ul class="filters">
<li>
<a
href="#/"
class="selected"
class:selected=move || mode() == Mode::All
class:selected={move || mode() == Mode::All}
>
"All"
</a>
</li>
<li>
<a href="#/active" class:selected=move || mode() == Mode::Active>
<a href="#/active" class:selected={move || mode() == Mode::Active}>
"Active"
</a>
</li>
<li>
<a href="#/completed" class:selected=move || mode() == Mode::Completed>
<a
href="#/completed"
class:selected={move || mode() == Mode::Completed}
>
"Completed"
</a>
</li>
</ul>
<button
class="clear-completed hidden"
class:hidden=move || todos.with(|t| t.completed() == 0)
on:click=move |_| set_todos.update(|t| t.clear_completed())
class:hidden={move || todos.with(|t| t.completed() == 0)}
on:click={move |_| set_todos.update(|t| t.clear_completed())}
>
"Clear completed"
</button>
Expand Down Expand Up @@ -264,26 +263,7 @@ pub fn Todo(todo: Todo) -> impl Render<Dom> + RenderHtml<Dom> {
};

view! {
<li class="todo" class:editing=editing class:completed=move || (todo.completed)()>
/* <div class="view">
<input class="toggle" r#type="checkbox"/>
<label on:dblclick=move |_| set_editing(true)>{move || todo.title.get()}</label>
<button
class="destroy"
on:click=move |_| set_todos.update(|t| t.remove(todo.id))
></button>
</div>
{move || {
editing()
.then(|| {
view! {
<input
class="edit"
class:hidden=move || !(editing)()
/>
}
})
}} */
<li class="todo" class:editing={editing} class:completed={move || (todo.completed)()}>
</li>
}
}
Expand Down
12 changes: 5 additions & 7 deletions examples/action-form-error-handling/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub fn App() -> impl IntoView {
// content for this welcome page
<Router>
<main id="app">
<FlatRoutes fallback=NotFound>
<Route path=StaticSegment("") view=HomePage/>
<FlatRoutes fallback={NotFound}>
<Route path={StaticSegment("")} view={HomePage} />
</FlatRoutes>
</main>
</Router>
Expand Down Expand Up @@ -48,12 +48,10 @@ fn HomePage() -> impl IntoView {

view! {
<h1>"Test the action form!"</h1>
<ErrorBoundary fallback=move |error| {
move || format!("{:#?}", error.get())
}>
<ErrorBoundary fallback={move |error| { move || format!("{:#?}", error.get()) }}>
<pre>{value}</pre>
<ActionForm action=do_something_action attr:class="form">
<label>"Should error: "<input type="checkbox" name="should_error"/></label>
<ActionForm action={do_something_action} attr:class="form">
<label>"Should error: "<input type="checkbox" name="should_error" /></label>
<button type="submit">Submit</button>
</ActionForm>
</ErrorBoundary>
Expand Down
10 changes: 5 additions & 5 deletions examples/action-form-error-handling/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ async fn main() -> std::io::Result<()> {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<AutoReload options=leptos_options.clone()/>
<HydrationScripts options=leptos_options.clone()/>
<MetaTags/>
<AutoReload options={leptos_options.clone()} />
<HydrationScripts options={leptos_options.clone()} />
<MetaTags />
</head>
<body>
<App/>
<App />
</body>
</html>
}
Expand Down
Loading