Update all libraries and examples to use new set_x API

This commit is contained in:
Greg Johnston 2022-10-08 20:39:13 -04:00
parent 6e5e18eb33
commit 2d2f2a52a4
19 changed files with 57 additions and 54 deletions

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.1" }
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.4" }
wee_alloc = "0.4"
console_log = "0.2"
log = "0.4"

View File

@ -5,9 +5,10 @@ pub fn simple_counter(cx: Scope) -> web_sys::Element {
view! {
<div>
<button on:click=move |_| set_value(|value| *value -= 1)>"-1"</button>
<button on:click=move |_| set_value(0)>"Clear"</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(|value| *value += 1)>"+1"</button>
<button on:click=move |_| set_value.update(|value| *value += 1)>"+1"</button>
</div>
}
}

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.1" }
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.4" }
wee_alloc = "0.4"
log = "0.4"
console_log = "0.2"

View File

@ -17,8 +17,8 @@ pub fn Counters(cx: Scope) -> web_sys::Element {
let add_counter = move |_| {
let id = next_counter_id();
let sig = create_signal(cx, 0);
set_counters(move |counters| counters.push((id, sig)));
set_next_counter_id(|id| *id += 1);
set_counters.update(move |counters| counters.push((id, sig)));
set_next_counter_id.update(|id| *id += 1);
};
let add_many_counters = move |_| {
@ -27,11 +27,11 @@ pub fn Counters(cx: Scope) -> web_sys::Element {
let signal = create_signal(cx, 0);
new_counters.push((next_id, signal));
}
set_counters(move |n| *n = new_counters.clone());
set_counters(new_counters.clone());
};
let clear_counters = move |_| {
set_counters(|counters| counters.clear());
set_counters.update(|counters| counters.clear());
};
view! {
@ -80,20 +80,18 @@ fn Counter(
) -> web_sys::Element {
let CounterUpdater { set_counters } = use_context(cx).unwrap_throw();
let input = move |ev| {
set_value(move |value| *value = event_target_value(&ev).parse::<i32>().unwrap_or_default())
};
let input = move |ev| set_value(event_target_value(&ev).parse::<i32>().unwrap_or_default());
view! {
<li>
<button on:click={move |_| set_value(move |value| *value -= 1)}>"-1"</button>
<button on:click={move |_| set_value.update(move |value| *value -= 1)}>"-1"</button>
<input type="text"
prop:value={move || value().to_string()}
on:input=input
/>
<span>{move || value().to_string()}</span>
<button on:click=move |_| set_value(move |value| *value += 1)>"+1"</button>
<button on:click=move |_| set_counters(move |counters| counters.retain(|(counter_id, _)| counter_id != &id))>"x"</button>
<button on:click=move |_| set_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>
</li>
}
}

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.58"
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.1" }
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.4" }
reqwasm = "0.5.0"
serde = { version = "1", features = ["derive"] }
wee_alloc = "0.4"

View File

@ -31,7 +31,7 @@ async fn fetch_cats(count: u32) -> Result<Vec<String>, ()> {
pub fn fetch_example(cx: Scope) -> web_sys::Element {
let (cat_count, set_cat_count) = create_signal::<u32>(cx, 1);
let cats = create_resource(cx, cat_count, |count| fetch_cats(*count));
let cats = create_resource(cx, cat_count, |count| fetch_cats(count));
view! {
<div>
@ -41,8 +41,7 @@ pub fn fetch_example(cx: Scope) -> web_sys::Element {
value={move || cat_count.get().to_string()}
on:input=move |ev| {
let val = event_target_value(&ev).parse::<u32>().unwrap_or(0);
log!("set_cat_count {val}");
set_cat_count(|n| *n = val);
set_cat_count(val);
}
/>
</label>

View File

@ -6,7 +6,8 @@ edition = "2021"
[dependencies]
console_log = "0.2"
log = "0.4"
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.1" }
leptos = { path = "../../leptos", features = ["csr"], version = "0.0.4" }
leptos_router = { path = "../../router", features = ["csr"], version = "0.0.4" }
wee_alloc = "0.4"
futures = "0.3"

View File

@ -1,4 +1,5 @@
use std::time::Duration;
use leptos::{Serialize, Deserialize};
use futures::{
channel::oneshot::{self, Canceled},
@ -6,14 +7,14 @@ use futures::{
};
use leptos::set_timeout;
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ContactSummary {
pub id: usize,
pub first_name: String,
pub last_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Contact {
pub id: usize,
pub first_name: String,

View File

@ -8,6 +8,7 @@ use std::{
use api::{Contact, ContactSummary};
use futures::Future;
use leptos::*;
use leptos_router::*;
use crate::api::{get_contact, get_contacts};
@ -102,7 +103,7 @@ pub fn Index(cx: Scope) -> Vec<Element> {
#[component]
pub fn ContactList(cx: Scope) -> Element {
let contacts = use_loader::<Resource<String, Vec<ContactSummary>>>(cx);
let contacts = use_loader::<(String, Vec<ContactSummary>)>(cx);
log::debug!(
"[ContactList] before <Suspense/>, use_route(cx).path() is {:?}",
@ -142,12 +143,12 @@ pub fn Contact(cx: Scope) -> Element {
view! {
<div class="contact">
<Suspense fallback=move || view! { <p>"Loading..."</p> }>{
move || contact.read().flatten().map(|contact| view! {
move || contact.read().map(|contact| contact.map(|contact| view! {
<section class="card">
<h1>{contact.first_name} " " {contact.last_name}</h1>
<p>{contact.address_1}<br/>{contact.address_2}</p>
</section>
})
}))
}</Suspense>
</div>
}

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { path = "../../leptos", version = "0.0.1" }
leptos = { path = "../../leptos" }
wee_alloc = "0.4"
miniserde = "0.1"
log = "0.4"

View File

@ -57,14 +57,14 @@ impl Todos {
if self.remaining() == 0 {
for todo in &self.0 {
if todo.completed.get() {
(todo.set_completed)(|completed| *completed = false);
(todo.set_completed)(false);
}
}
}
// otherwise, mark them all complete
else {
for todo in &self.0 {
(todo.set_completed)(|completed| *completed = true);
(todo.set_completed)(true);
}
}
}
@ -101,7 +101,8 @@ impl Todo {
}
pub fn toggle(&self) {
(self.set_completed)(|completed| *completed = !*completed);
self.set_completed
.update(|completed| *completed = !*completed);
}
}
@ -124,7 +125,7 @@ pub fn TodoMVC(cx: Scope, todos: Todos) -> Element {
let (mode, set_mode) = create_signal(cx, Mode::All);
window_event_listener("hashchange", move |_| {
let new_mode = location_hash().map(|hash| route(&hash)).unwrap_or_default();
set_mode(|mode| *mode = new_mode);
set_mode(new_mode);
});
let add_todo = move |ev: web_sys::Event| {
@ -240,9 +241,9 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
if value.is_empty() {
set_todos.update(|t| t.remove(todo.id));
} else {
(todo.set_title)(move |n| *n = value.to_string());
(todo.set_title)(value.to_string());
}
set_editing(|n| *n = false);
set_editing(false);
};
let tpl = view! {
@ -259,10 +260,10 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
prop:checked={move || (todo.completed)()}
on:input={move |ev| {
let checked = event_target_checked(&ev);
(todo.set_completed)(|n| *n = checked);
(todo.set_completed)(checked);
}}
/>
<label on:dblclick={move |_| set_editing(|n| *n = true)}>
<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))}/>
@ -278,7 +279,7 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
if key_code == ENTER_KEY {
save(&event_target_value(&ev));
} else if key_code == ESCAPE_KEY {
set_editing(|n| *n = false);
set_editing(false);
}
}}
/>

View File

@ -1,6 +1,6 @@
[package]
name = "leptos"
version = "0.0.3"
version = "0.0.4"
edition = "2021"
authors = ["Greg Johnston"]
license = "MIT"
@ -8,12 +8,13 @@ repository = "https://github.com/gbj/leptos"
description = "Leptos is a full-stack, isomorphic Rust web framework leveraging fine-grained reactivity to build declarative user interfaces."
[dependencies]
leptos_core = { path = "../leptos_core", version = "0.0.3" }
leptos_dom = { path = "../leptos_dom", version = "0.0.3" }
leptos_core = { path = "../leptos_core", version = "0.0.4" }
leptos_dom = { path = "../leptos_dom", version = "0.0.4" }
leptos_macro = { path = "../leptos_macro", version = "0.0.3" }
leptos_reactive = { path = "../leptos_reactive", version = "0.0.3" }
leptos_reactive = { path = "../leptos_reactive", version = "0.0.4" }
[features]
csr = ["leptos_core/csr", "leptos_macro/csr", "leptos_reactive/csr"]
hydrate = ["leptos_core/hydrate", "leptos_macro/hydrate", "leptos_reactive/hydrate"]
ssr = ["leptos_core/ssr", "leptos_macro/ssr", "leptos_reactive/ssr"]
transition = ["leptos_reactive/transition"]

View File

@ -1,6 +1,6 @@
[package]
name = "leptos_core"
version = "0.0.3"
version = "0.0.4"
edition = "2021"
authors = ["Greg Johnston"]
license = "MIT"
@ -8,9 +8,9 @@ repository = "https://github.com/gbj/leptos"
description = "Core functionality for the Leptos web framework."
[dependencies]
leptos_dom = { path = "../leptos_dom", version = "0.0.3" }
leptos_dom = { path = "../leptos_dom", version = "0.0.4" }
leptos_macro = { path = "../leptos_macro", version = "0.0.3" }
leptos_reactive = { path = "../leptos_reactive", version = "0.0.3" }
leptos_reactive = { path = "../leptos_reactive", version = "0.0.4" }
log = "0.4"
[features]

View File

@ -1,6 +1,6 @@
[package]
name = "leptos_dom"
version = "0.0.3"
version = "0.0.4"
edition = "2021"
authors = ["Greg Johnston"]
license = "MIT"
@ -9,7 +9,7 @@ description = "DOM operations for the Leptos web framework."
[dependencies]
js-sys = "0.3"
leptos_reactive = { path = "../leptos_reactive", version = "0.0.3" }
leptos_reactive = { path = "../leptos_reactive", version = "0.0.4" }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4.31"
wee_alloc = "0.4.5"

View File

@ -17,7 +17,7 @@ js-sys = { version = "0.3", optional = true }
serde-wasm-bindgen = { version = "0.4", optional = true }
serde_json = { version = "1", optional = true }
base64 = { version = "0.13", optional = true }
bincode = "1"
# bincode = "1"
thiserror = "1"
tokio = { version = "1", features = ["rt"], optional = true }
wasm-bindgen = { version = "0.2", optional = true }

View File

@ -8,7 +8,7 @@ repository = "https://github.com/gbj/leptos"
description = "Tools to set HTML metadata in the Leptos web framework."
[dependencies]
leptos = { path = "../leptos", version = "0.0.1" }
leptos = { path = "../leptos", version = "0.0.4" }
log = "0.4"
[dependencies.web-sys]

View File

@ -1,6 +1,6 @@
[package]
name = "leptos_router"
version = "0.0.1"
version = "0.0.4"
edition = "2021"
authors = ["Greg Johnston"]
license = "MIT"
@ -8,7 +8,7 @@ repository = "https://github.com/gbj/leptos"
description = "Router for the Leptos web framework."
[dependencies]
leptos = { path = "../leptos", version = "0.0.1" }
leptos = { path = "../leptos", version = "0.0.4" }
common_macros = "0.1"
itertools = "0.10"
lazy_static = "1"

View File

@ -124,14 +124,14 @@ impl RouterContext {
if value != reference() {
#[cfg(feature = "transition")]
transition.start(move || {
set_reference(move |r| *r = value.clone());
set_state(move |s| *s = state.clone());
set_reference.update(move |r| *r = value.clone());
set_state.update(move |s| *s = state.clone());
});
#[cfg(not(feature = "transition"))]
{
set_reference(move |r| *r = value.clone());
set_state(move |s| *s = state.clone());
set_reference.update(move |r| *r = value.clone());
set_state.update(move |s| *s = state.clone());
}
}
});

View File

@ -68,13 +68,13 @@ impl History for BrowserIntegration {
Ok(_) => log::debug!("navigated"),
Err(e) => log::error!("{e:#?}"),
};
set_location(|change| *change = Self::current());
set_location.update(|change| *change = Self::current());
} else {
log::debug!("RouterContext not found");
}
//Self::navigate(&Self {}, &Self::current());
//set_location(|change| *change = Self::current());
//set_location.update(|change| *change = Self::current());
});
location