reorganizing exports and updating examples

This commit is contained in:
Greg Johnston 2024-04-28 20:52:59 -04:00
parent 4336051f78
commit b24eaedfe9
28 changed files with 231 additions and 287 deletions

View File

@ -40,7 +40,7 @@ members = [
exclude = ["benchmarks", "examples"]
[workspace.package]
version = "0.7.0-preview"
version = "0.7.0-preview2"
rust-version = "1.75"
[workspace.dependencies]
@ -49,23 +49,23 @@ any_spawner = { path = "./any_spawner/", version = "0.1" }
const_str_slice_concat = { path = "./const_str_slice_concat", version = "0.1" }
either_of = { path = "./either_of/", version = "0.1" }
hydration_context = { path = "./hydration_context", version = "0.1" }
leptos = { path = "./leptos", version = "0.7.0-preview" }
leptos_config = { path = "./leptos_config", version = "0.7.0-preview" }
leptos_dom = { path = "./leptos_dom", version = "0.7.0-preview" }
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.7.0-preview" }
leptos_integration_utils = { path = "./integrations/utils", version = "0.7.0-preview" }
leptos_macro = { path = "./leptos_macro", version = "0.7.0-preview" }
leptos_reactive = { path = "./leptos_reactive", version = "0.7.0-preview" }
leptos_router = { path = "./router", version = "0.7.0-preview" }
leptos_server = { path = "./leptos_server", version = "0.7.0-preview" }
leptos_meta = { path = "./meta", version = "0.7.0-preview" }
leptos = { path = "./leptos", version = "0.7.0-preview2" }
leptos_config = { path = "./leptos_config", version = "0.7.0-preview2" }
leptos_dom = { path = "./leptos_dom", version = "0.7.0-preview2" }
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.7.0-preview2" }
leptos_integration_utils = { path = "./integrations/utils", version = "0.7.0-preview2" }
leptos_macro = { path = "./leptos_macro", version = "0.7.0-preview2" }
leptos_reactive = { path = "./leptos_reactive", version = "0.7.0-preview2" }
leptos_router = { path = "./router", version = "0.7.0-preview2" }
leptos_server = { path = "./leptos_server", version = "0.7.0-preview2" }
leptos_meta = { path = "./meta", version = "0.7.0-preview2" }
next_tuple = { path = "./next_tuple", version = "0.1.0-preview" }
oco_ref = { path = "./oco", version = "0.2" }
or_poisoned = { path = "./or_poisoned", version = "0.1" }
reactive_graph = { path = "./reactive_graph", version = "0.1.0-preview" }
server_fn = { path = "./server_fn", version = "0.7.0-preview" }
server_fn_macro = { path = "./server_fn_macro", version = "0.7.0-preview" }
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.7.0-preview" }
server_fn = { path = "./server_fn", version = "0.7.0-preview2" }
server_fn_macro = { path = "./server_fn_macro", version = "0.7.0-preview2" }
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.7.0-preview2" }
tachys = { path = "./tachys", version = "0.1.0-preview" }
[profile.release]

View File

@ -1,4 +1,4 @@
use leptos::{component, create_signal, prelude::*, view, IntoView};
use leptos::prelude::*;
/// A simple counter component.
///
@ -10,7 +10,7 @@ pub fn SimpleCounter(
/// The change that should be applied each time the button is clicked.
step: i32,
) -> impl IntoView {
let (value, set_value) = create_signal(initial_value);
let (value, set_value) = signal(initial_value);
view! {
<div>

View File

@ -1,15 +1,10 @@
use counter::SimpleCounter;
use leptos::*;
use leptos::prelude::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| {
view! {
<SimpleCounter
initial_value=0
step=1
/>
}
view! { <SimpleCounter initial_value=0 step=1/> }
})
}

View File

@ -1,14 +1,5 @@
use leptos::{
component,
prelude::*,
reactive_graph::{
owner::{provide_context, use_context},
signal::{
create_signal, ArcRwSignal, ReadSignal, RwSignal, WriteSignal,
},
},
view, For, IntoView,
};
use leptos::prelude::signal::*;
use leptos::prelude::*;
const MANY_COUNTERS: usize = 1000;
@ -49,26 +40,17 @@ pub fn Counters() -> impl IntoView {
view! {
<div>
<button on:click=add_counter>
"Add Counter"
</button>
<button on:click=add_many_counters>
{format!("Add {MANY_COUNTERS} Counters")}
</button>
<button on:click=clear_counters>
"Clear Counters"
</button>
<button on:click=add_counter>"Add Counter"</button>
<button on:click=add_many_counters>{format!("Add {MANY_COUNTERS} Counters")}</button>
<button on:click=clear_counters>"Clear Counters"</button>
<p>
"Total: "
<span>{move ||
counters.get()
.iter()
.map(|(_, count)| count.get())
.sum::<i32>()
.to_string()
}</span>
" from "
<span>{move || counters.get().len().to_string()}</span>
<span>
{move || {
counters.get().iter().map(|(_, count)| count.get()).sum::<i32>().to_string()
}}
</span> " from " <span>{move || counters.get().len().to_string()}</span>
" counters."
</p>
<ul>
@ -76,11 +58,10 @@ pub fn Counters() -> impl IntoView {
each=move || counters.get()
key=|counter| counter.0
children=move |(id, value)| {
view! {
<Counter id value/>
}
view! { <Counter id value/> }
}
/>
</ul>
</div>
}
@ -94,13 +75,20 @@ fn Counter(id: usize, value: ArcRwSignal<i32>) -> impl IntoView {
view! {
<li>
<button on:click=move |_| value.update(move |value| *value -= 1)>"-1"</button>
<input type="text"
<input
type="text"
prop:value=value
on:input:target=move |ev| { value.set(ev.target().value().parse::<i32>().unwrap_or_default()) }
on:input:target=move |ev| {
value.set(ev.target().value().parse::<i32>().unwrap_or_default())
}
/>
<span>{value.clone()}</span>
<button on:click=move |_| value.update(move |value| *value += 1)>"+1"</button>
<button on:click=move |_| set_counters.update(move |counters| counters.retain(|(counter_id, _)| counter_id != &id))>"x"</button>
<button on:click=move |_| {
set_counters
.update(move |counters| counters.retain(|(counter_id, _)| counter_id != &id))
}>"x"</button>
</li>
}
}

View File

@ -1,5 +1,5 @@
use counters::Counters;
use leptos::*;
use leptos::prelude::*;
fn main() {
_ = console_log::init_with_level(log::Level::Debug);

View File

@ -1,4 +1,4 @@
use leptos::{component, prelude::*, signal, view, ErrorBoundary, IntoView};
use leptos::prelude::*;
#[component]
pub fn App() -> impl IntoView {
@ -40,8 +40,8 @@ pub fn App() -> impl IntoView {
<p>
// because `value` is `Result<i32, _>`,
"You entered " // it will render the `i32` if it is `Ok`,
// and render nothing and trigger the error boundary
// it will render the `i32` if it is `Ok`,
"You entered " // and render nothing and trigger the error boundary
// if it is `Err`. It's a signal, so this will dynamically
// update when `value` changes
<strong>{value}</strong>

View File

@ -1,12 +1,8 @@
use error_boundary::*;
use leptos::*;
use leptos::prelude::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| {
view! {
<App/>
}
})
mount_to_body(App)
}

View File

@ -1,12 +1,4 @@
use leptos::{
error::Result,
prelude::*,
reactive_graph::{
computed::AsyncDerived,
signal::{signal, ArcRwSignal},
},
suspend, view, ErrorBoundary, Errors, IntoView, Transition,
};
use leptos::prelude::*;
use serde::{Deserialize, Serialize};
use thiserror::Error;
@ -55,8 +47,7 @@ pub fn fetch_example() -> impl IntoView {
// 2) we'd need to make sure there was a thread-local spawner set up
let cats = AsyncDerived::new_unsync(move || fetch_cats(cat_count.get()));
let fallback = move |errors: &ArcRwSignal<Errors>| {
let errors = errors.clone();
let fallback = move |errors: ArcRwSignal<Errors>| {
let error_list = move || {
errors.with(|errors| {
errors
@ -86,16 +77,27 @@ pub fn fetch_example() -> impl IntoView {
set_cat_count.set(val);
}
/>
</label>
<Transition fallback=|| view! { <div>"Loading..."</div> }>
<ErrorBoundary fallback>
<ul>
{suspend!(cats.await.map(|cats| {
cats.into_iter()
.map(|s| view! { <li><img src={s}/></li> })
.collect::<Vec<_>>()
}))}
</ul>
<ul>
{move || Suspend(async move {
cats.await
.map(|cats| {
cats.into_iter()
.map(|s| {
view! {
<li>
<img src=s/>
</li>
}
})
.collect::<Vec<_>>()
})
})}
</ul>
</ErrorBoundary>
</Transition>
</div>

View File

@ -1,5 +1,5 @@
use fetch::fetch_example;
use leptos::*;
use leptos::prelude::*;
pub fn main() {
use tracing_subscriber::fmt;

View File

@ -1,4 +1,4 @@
use leptos::*;
use leptos::prelude::*;
use rand::prelude::*;
use std::sync::atomic::{AtomicUsize, Ordering};
static ADJECTIVES: &[&str] = &[
@ -86,13 +86,8 @@ fn Button(
text: &'static str,
) -> impl IntoView {
view! {
<div class="col-sm-6 smallpad">
<button
id=id
class="btn btn-primary btn-block"
type="button"
>
<button id=id class="btn btn-primary btn-block" type="button">
{text}
</button>
</div>
@ -146,19 +141,20 @@ pub fn App() -> impl IntoView {
let is_selected = create_selector(move || selected.get());
view! {
<div class="container">
<div class="jumbotron">
<div class="row">
<div class="col-md-6"><h1>"Leptos"</h1></div>
<div class="col-md-6">
<h1>"Leptos"</h1>
</div>
<div class="col-md-6">
<div class="row">
<Button id="run" text="Create 1,000 rows" on:click=run />
<Button id="runlots" text="Create 10,000 rows" on:click=run_lots />
<Button id="add" text="Append 1,000 rows" on:click=add />
<Button id="update" text="Update every 10th row" on:click=update />
<Button id="clear" text="Clear" on:click=clear />
<Button id="swaprows" text="Swap Rows" on:click=swap_rows />
<Button id="run" text="Create 1,000 rows" on:click=run/>
<Button id="runlots" text="Create 10,000 rows" on:click=run_lots/>
<Button id="add" text="Append 1,000 rows" on:click=add/>
<Button id="update" text="Update every 10th row" on:click=update/>
<Button id="clear" text="Clear" on:click=clear/>
<Button id="swaprows" text="Swap Rows" on:click=swap_rows/>
</div>
</div>
</div>
@ -167,7 +163,7 @@ pub fn App() -> impl IntoView {
<tbody>
<For
each=move || data.get()
key={|row| row.id}
key=|row| row.id
children=move |row: RowData| {
let row_id = row.id;
let (label, _) = row.label;
@ -189,9 +185,10 @@ pub fn App() -> impl IntoView {
}
}
/>
</tbody>
</table>
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true" />
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
</div>
}
}

View File

@ -1,13 +1,4 @@
use leptos::{
callback::{Callback, UnsyncCallback},
component,
prelude::*,
reactive_graph::{
owner::{provide_context, use_context},
signal::{signal, WriteSignal},
},
view, IntoView,
};
use leptos::prelude::*;
use web_sys::MouseEvent;
// This highlights four different ways that child components can communicate
@ -56,7 +47,10 @@ pub fn App() -> impl IntoView {
// Button C: use a regular event listener
// setting an event listener on a component like this applies it
// to each of the top-level elements the component returns
<ButtonC on:click=move |_| set_italics.update(|value| *value = !*value)/>
//
// TODO sorry <ButtonC/> I need to take another crack at `on:` here!
//
// <ButtonC on:click=move |_| set_italics.update(|value| *value = !*value)/>
// Button D gets its setter from context rather than props
<ButtonD/>
@ -70,14 +64,7 @@ pub fn ButtonA(
/// Signal that will be toggled when the button is clicked.
setter: WriteSignal<bool>,
) -> impl IntoView {
view! {
<button
on:click=move |_| setter.update(|value| *value = !*value)
>
"Toggle Red"
</button>
}
view! { <button on:click=move |_| setter.update(|value| *value = !*value)>"Toggle Red"</button> }
}
/// Button B receives a closure
@ -89,13 +76,7 @@ pub fn ButtonB<F>(
where
F: FnMut(MouseEvent) + 'static,
{
view! {
<button
on:click=on_click
>
"Toggle Right"
</button>
}
view! { <button on:click=on_click>"Toggle Right"</button> }
}
use leptos::tachys::view::add_attr::AddAnyAttr;
@ -104,11 +85,7 @@ use leptos::tachys::view::add_attr::AddAnyAttr;
/// its click. Instead, the parent component adds an event listener.
#[component]
pub fn ButtonC() -> impl IntoView + AddAnyAttr<Dom> {
view! {
<button>
"Toggle Italics"
</button>
}
view! { <button>"Toggle Italics"</button> }
}
/// Button D is very similar to Button A, but instead of passing the setter as a prop
@ -118,10 +95,8 @@ pub fn ButtonD() -> impl IntoView {
let setter = use_context::<SmallcapsContext>().unwrap().0;
view! {
<button
on:click=move |_| setter.update(|value| *value = !*value)
>
"Toggle Small Caps"
</button>
<button on:click=move |_| {
setter.update(|value| *value = !*value)
}>"Toggle Small Caps"</button>
}
}

View File

@ -1,8 +1,8 @@
use leptos::*;
use leptos::prelude::*;
use parent_child::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| view! { <App/> })
mount_to_body(App)
}

View File

@ -1,20 +1,8 @@
mod api;
use crate::api::*;
use leptos::{
component,
prelude::*,
reactive_graph::{
computed::AsyncDerived,
effect::Effect,
owner::{provide_context, use_context, Owner},
signal::ArcRwSignal,
},
suspend,
tachys::either::Either,
view, IntoView, Params, Suspense, Transition,
};
use log::{debug, info};
use routing::{
use leptos::either::Either;
use leptos::prelude::*;
use leptos_router::{
components::{ParentRoute, Redirect, Route, Router, Routes},
hooks::{use_location, use_navigate, use_params},
link::A,
@ -22,6 +10,7 @@ use routing::{
params::Params,
MatchNestedRoutes, NestedRoute, Outlet, ParamSegment, StaticSegment,
};
use log::{debug, info};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct ExampleContext(i32);
@ -66,7 +55,7 @@ pub fn RouterExample() -> impl IntoView {
#[component]
pub fn ContactRoutes() -> impl MatchNestedRoutes<Dom> + Clone {
view! {
<ParentRoute path=StaticSegment("contacts") view=ContactList>
<ParentRoute path=StaticSegment("") view=ContactList>
<Route path=StaticSegment("") view=|| "Select a contact."/>
<Route path=ParamSegment("id") view=Contact/>
</ParentRoute>
@ -87,17 +76,23 @@ pub fn ContactList() -> impl IntoView {
let location = use_location();
let contacts =
AsyncDerived::new(move || get_contacts(location.search.get()));
let contacts = suspend!(
let contacts = move || {
Suspend(async move {
// this data doesn't change frequently so we can use .map().collect() instead of a keyed <For/>
contacts.await
.into_iter()
.map(|contact| {
view! {
<li><A href=contact.id.to_string()><span>{contact.first_name} " " {contact.last_name}</span></A></li>
<li>
<A href=contact.id.to_string()>
<span>{contact.first_name} " " {contact.last_name}</span>
</A>
</li>
}
})
.collect::<Vec<_>>()
);
})
};
view! {
<div class="contact-list">
<h1>"Contacts"</h1>
@ -139,16 +134,21 @@ pub fn Contact() -> impl IntoView {
)
});
let contact_display = suspend!(match contact.await {
None =>
Either::Left(view! { <p>"No contact with this ID was found."</p> }),
Some(contact) => Either::Right(view! {
<section class="card">
<h1>{contact.first_name} " " {contact.last_name}</h1>
<p>{contact.address_1} <br/> {contact.address_2}</p>
</section>
}),
});
let contact_display = move || {
Suspend(async move {
match contact.await {
None => Either::Left(
view! { <p>"No contact with this ID was found."</p> },
),
Some(contact) => Either::Right(view! {
<section class="card">
<h1>{contact.first_name} " " {contact.last_name}</h1>
<p>{contact.address_1} <br/> {contact.address_2}</p>
</section>
}),
}
})
};
view! {
<div class="contact">

View File

@ -1,16 +1,16 @@
use leptos::*;
use leptos::prelude::*;
use router::*;
use tracing_subscriber::fmt;
use tracing_subscriber_wasm::MakeConsoleWriter;
pub fn main() {
/*fmt()
.with_writer(
MakeConsoleWriter::default()
.map_trace_level_to(tracing::Level::DEBUG),
)
.without_time()
.init();*/
.with_writer(
MakeConsoleWriter::default()
.map_trace_level_to(tracing::Level::DEBUG),
)
.without_time()
.init();*/
console_error_panic_hook::set_once();
mount_to_body(RouterExample);
}

View File

@ -2,7 +2,8 @@
#[tokio::main]
async fn main() {
use axum::Router;
use leptos::{logging::log, config::get_configuration, view, HydrationScripts};
use leptos::prelude::*;
use leptos::logging;
use leptos_axum::{generate_route_list, LeptosRoutes};
use ssr_modes_axum::{app::*, fallback::file_and_error_handler};
use leptos_meta::MetaTags;

View File

@ -1,9 +1,5 @@
use crate::errors::TodoAppError;
use leptos::context::use_context;
use leptos::reactive_graph::effect::Effect;
use leptos::signals::RwSignal;
use leptos::{component, server, view, For, IntoView};
use leptos::{prelude::*, Errors};
use leptos::prelude::*;
#[cfg(feature = "ssr")]
use leptos_axum::ResponseOptions;

View File

@ -5,8 +5,7 @@ use axum::{
http::{Request, Response, StatusCode, Uri},
response::{IntoResponse, Response as AxumResponse},
};
use leptos::config::LeptosOptions;
use leptos::{view, Errors};
use leptos::prelude::*;
use tower::ServiceExt;
use tower_http::services::ServeDir;
@ -25,7 +24,7 @@ pub async fn file_and_error_handler(
errors.insert_with_default_key(TodoAppError::NotFound);
let handler = leptos_axum::render_app_to_stream(
options.to_owned(),
move || view! {<ErrorTemplate outside_errors=errors.clone()/>},
move || view! { <ErrorTemplate outside_errors=errors.clone()/> },
);
handler(req).await.into_response()
}

View File

@ -8,7 +8,7 @@ pub mod todo;
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {
use crate::todo::TodoApp;
use tracing_subscriber::fmt;
/* use tracing_subscriber::fmt;
use tracing_subscriber_wasm::MakeConsoleWriter;
fmt()
@ -22,8 +22,8 @@ pub fn hydrate() {
// a runtime error.
.without_time()
.init();
_ = console_log::init_with_level(log::Level::Error);
_ = console_log::init_with_level(log::Level::Error);*/
console_error_panic_hook::set_once();
leptos::hydrate_body(TodoApp);
leptos::mount::hydrate_body(TodoApp);
}

View File

@ -7,11 +7,7 @@ use axum::{
routing::get,
Router,
};
use leptos::{
config::{get_configuration, LeptosOptions},
view,
};
use leptos::{context::provide_context, HydrationScripts};
use leptos::prelude::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use todo_app_sqlite_axum::*;

View File

@ -1,13 +1,6 @@
use crate::error_template::ErrorTemplate;
use leptos::context::use_context;
use leptos::reactive_graph::effect::Effect;
use leptos::server::{Resource, ServerAction, ServerMultiAction};
use leptos::tachys::either::Either;
use leptos::{
component, server, suspend, view, ActionForm, ErrorBoundary, IntoView,
MultiActionForm,
};
use leptos::{prelude::*, Suspense, Transition};
use leptos::either::Either;
use leptos::prelude::*;
use serde::{Deserialize, Serialize};
use server_fn::codec::SerdeLite;
use server_fn::ServerFnError;

View File

@ -1,17 +1,6 @@
use leptos::{
leptos_dom::{
events,
helpers::{location_hash, window, window_event_listener},
},
prelude::*,
reactive_graph::{
effect::Effect,
owner::{provide_context, use_context},
signal::{RwSignal, WriteSignal},
},
tachys::{html::element::Input, reactive_graph::node_ref::NodeRef},
*,
};
use leptos::ev;
use leptos::html::Input;
use leptos::prelude::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use web_sys::KeyboardEvent;
@ -156,7 +145,7 @@ pub fn TodoMVC() -> impl IntoView {
// Handle the three filter modes: All, Active, and Completed
let (mode, set_mode) = signal(Mode::All);
window_event_listener(events::hashchange, move |_| {
window_event_listener(ev::hashchange, move |_| {
let new_mode =
location_hash().map(|hash| route(&hash)).unwrap_or_default();
set_mode.set(new_mode);
@ -237,46 +226,57 @@ pub fn TodoMVC() -> impl IntoView {
node_ref=input_ref
/>
</header>
<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)}
<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 |_| todos.with(|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
let:todo
>
<For each=filtered_todos key=|todo| todo.id let:todo>
<Todo todo/>
</For>
</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.get() == Mode::All}>"All"</a></li>
<li><a href="#/active" class:selected={move || mode.get() == Mode::Active}>"Active"</a></li>
<li><a href="#/completed" class:selected={move || mode.get() == Mode::Completed}>"Completed"</a></li>
<li>
<a
href="#/"
class="selected"
class:selected=move || mode.get() == Mode::All
>
"All"
</a>
</li>
<li>
<a href="#/active" class:selected=move || mode.get() == Mode::Active>
"Active"
</a>
</li>
<li>
<a
href="#/completed"
class:selected=move || mode.get() == Mode::Completed
>
"Completed"
</a>
</li>
</ul>
<button
class="clear-completed hidden"
class:hidden={move || todos.with(|t| t.completed() == 0)}
class:hidden=move || todos.with(|t| t.completed() == 0)
on:click=move |_| set_todos.update(|t| t.clear_completed())
>
"Clear completed"
@ -285,8 +285,8 @@ pub fn TodoMVC() -> impl IntoView {
</section>
<footer class="info">
<p>"Double-click to edit a todo"</p>
<p>"Created by "<a href="http://todomvc.com">"Greg Johnston"</a></p>
<p>"Part of "<a href="http://todomvc.com">"TodoMVC"</a></p>
<p>"Created by " <a href="http://todomvc.com">"Greg Johnston"</a></p>
<p>"Part of " <a href="http://todomvc.com">"TodoMVC"</a></p>
</footer>
</main>
}
@ -312,49 +312,52 @@ pub fn Todo(todo: Todo) -> impl IntoView {
};
view! {
<li
class="todo"
class:editing={editing}
class:completed={move || todo.completed.get()}
>
<li class="todo" class:editing=editing class:completed=move || todo.completed.get()>
<div class="view">
<input
node_ref=todo_input
class="toggle"
type="checkbox"
prop:checked={move || todo.completed.get()}
on:input:target={move |ev| {
prop:checked=move || todo.completed.get()
on:input:target=move |ev| {
todo.completed.set(ev.target().checked());
}}
}
/>
<label on:dblclick=move |_| {
set_editing.set(true);
if let Some(input) = todo_input.get() {
_ = input.focus();
}
}>
{todo.title}
</label>
<button class="destroy" on:click=move |_| set_todos.update(|t| t.remove(todo.id))/>
}>{move || todo.title.get()}</label>
<button
class="destroy"
on:click=move |_| set_todos.update(|t| t.remove(todo.id))
></button>
</div>
{move || editing.get().then(|| view! {
<input
class="edit"
class:hidden={move || !editing.get()}
prop:value={move || todo.title.get()}
on:focusout:target=move |ev| save(&ev.target().value())
on:keyup:target={move |ev| {
let key_code = ev.key_code();
if key_code == ENTER_KEY {
save(&ev.target().value());
} else if key_code == ESCAPE_KEY {
set_editing.set(false);
{move || {
editing
.get()
.then(|| {
view! {
<input
class="edit"
class:hidden=move || !editing.get()
prop:value=move || todo.title.get()
on:focusout:target=move |ev| save(&ev.target().value())
on:keyup:target=move |ev| {
let key_code = ev.key_code();
if key_code == ENTER_KEY {
save(&ev.target().value());
} else if key_code == ESCAPE_KEY {
set_editing.set(false);
}
}
/>
}
}}
/>
})
}
})
}}
</li>
}
}

View File

@ -1,7 +1,7 @@
use leptos::*;
use leptos::prelude::*;
pub use todomvc::*;
fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| view! { <TodoMVC/> })
mount_to_body(TodoMVC)
}

View File

@ -237,9 +237,9 @@ pub async fn handle_server_fns(req: Request<Body>) -> impl IntoResponse {
fn init_executor() {
#[cfg(feature = "wasm")]
let _ = leptos::Executor::init_wasm_bindgen();
let _ = any_spawner::Executor::init_wasm_bindgen();
#[cfg(all(not(feature = "wasm"), feature = "default"))]
let _ = leptos::Executor::init_tokio();
let _ = any_spawner::Executor::init_tokio();
#[cfg(all(not(feature = "wasm"), not(feature = "default")))]
{
eprintln!(

View File

@ -15,6 +15,7 @@ any_spawner = { workspace = true, features = ["wasm-bindgen"] }
base64 = { version = "0.22", optional = true }
cfg-if = "1"
hydration_context = { workspace = true }
either_of = { workspace = true }
leptos_dom = { workspace = true }
leptos_macro = { workspace = true }
leptos_reactive = { workspace = true }

View File

@ -161,18 +161,19 @@ pub mod prelude {
#[cfg(feature = "nonce")]
pub use crate::nonce::*;
pub use crate::{
callback::*, children::*, component::*, context::*,
control_flow::*, error::*, form::*, hydration::*, into_view::*,
suspense::*,
callback::*, children::*, component::*, control_flow::*, error::*,
form::*, hydration::*, into_view::*, mount::*, suspense::*,
};
pub use leptos_config::*;
pub use leptos_dom::*;
pub use leptos_dom::{helpers::*, *};
pub use leptos_macro::*;
pub use leptos_server::*;
pub use oco_ref::*;
pub use reactive_graph::*;
pub use server_fn::*;
pub use tachys;
pub use reactive_graph::{
computed::*, effect::*, owner::*, signal::*, *,
};
pub use server_fn::{self, ServerFnError};
pub use tachys::{self, reactive_graph::node_ref::*};
}
pub use export_types::*;
}
@ -237,6 +238,7 @@ pub mod mount;
pub use leptos_config as config;
pub use oco_ref as oco;
mod from_form_data;
pub use either_of as either;
pub use reactive_graph;
/// Provide and access data along the reactive graph, sharing data without directly passing arguments.

View File

@ -1,6 +1,6 @@
[package]
name = "leptos_meta"
version = "0.7.0-preview"
version = "0.7.0-preview2"
edition = "2021"
authors = ["Greg Johnston"]
license = "MIT"

View File

@ -1,6 +1,6 @@
[package]
name = "leptos_router"
version = "0.6.13"
version = "0.7.0-preview2"
edition = "2021"
authors = ["Greg Johnston", "Ben Wishovich"]
license = "MIT"

View File

@ -1,6 +1,6 @@
[package]
name = "leptos_router"
version = "0.7.0-preview"
version = "0.7.0-preview2"
edition = "2021"
authors = ["Greg Johnston", "Ben Wishovich"]
license = "MIT"