"Part of " "TodoMVC"
diff --git a/Cargo.toml b/Cargo.toml index 2ccc8a84f..23035d3e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,22 +26,22 @@ members = [ exclude = ["benchmarks", "examples"] [workspace.package] -version = "0.4.9" +version = "0.5.0" [workspace.dependencies] -leptos = { path = "./leptos", version = "0.4.9" } -leptos_dom = { path = "./leptos_dom", version = "0.4.9" } -leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.4.9" } -leptos_macro = { path = "./leptos_macro", version = "0.4.9" } -leptos_reactive = { path = "./leptos_reactive", version = "0.4.9" } -leptos_server = { path = "./leptos_server", version = "0.4.9" } -server_fn = { path = "./server_fn", version = "0.4.9" } -server_fn_macro = { path = "./server_fn_macro", version = "0.4.9" } -server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.4.9" } -leptos_config = { path = "./leptos_config", version = "0.4.9" } -leptos_router = { path = "./router", version = "0.4.9" } -leptos_meta = { path = "./meta", version = "0.4.9" } -leptos_integration_utils = { path = "./integrations/utils", version = "0.4.9" } +leptos = { path = "./leptos", version = "0.5.0" } +leptos_dom = { path = "./leptos_dom", version = "0.5.0" } +leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.5.0" } +leptos_macro = { path = "./leptos_macro", version = "0.5.0" } +leptos_reactive = { path = "./leptos_reactive", version = "0.5.0" } +leptos_server = { path = "./leptos_server", version = "0.5.0" } +server_fn = { path = "./server_fn", version = "0.5.0" } +server_fn_macro = { path = "./server_fn_macro", version = "0.5.0" } +server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.5.0" } +leptos_config = { path = "./leptos_config", version = "0.5.0" } +leptos_router = { path = "./router", version = "0.5.0" } +leptos_meta = { path = "./meta", version = "0.5.0" } +leptos_integration_utils = { path = "./integrations/utils", version = "0.5.0" } [profile.release] codegen-units = 1 diff --git a/README.md b/README.md index 4234fb16b..a0258c47e 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ use leptos::*; #[component] -pub fn SimpleCounter(cx: Scope, initial_value: i32) -> impl IntoView { +pub fn SimpleCounter(initial_value: i32) -> impl IntoView { // create a reactive signal with the initial value - let (value, set_value) = create_signal(cx, initial_value); + let (value, set_value) = create_signal(initial_value); // create event handlers for our buttons // note that `value` and `set_value` are `Copy`, so it's super easy to move them into closures @@ -27,19 +27,22 @@ pub fn SimpleCounter(cx: Scope, initial_value: i32) -> impl IntoView { let increment = move |_| set_value.update(|value| *value += 1); // create user interfaces with the declarative `view!` macro - view! { cx, + view! {
"Part of " "TodoMVC"
{move || format!("{:#?}", resources.get().into_iter().map(|(id, resource)| (id, resource.get())).collect::>())}
@@ -55,17 +55,17 @@ pub fn App(cx: Scope) -> impl IntoView {
}
```
-Clicking the button twice will cause a panic, because of the nested signal *read*. Calling the `update` function on `resources` immediately takes out a mutable borrow on `resources`, then updates the `resource` signal—which re-runs the effect that reads from the signals, which tries to immutably access `resources` and panics. It's the nested update here which causes a problem, because the inner update triggers and effect that tries to read both signals while the outer is still updating.
+Clicking the button twice will cause a panic, because of the nested signal _read_. Calling the `update` function on `resources` immediately takes out a mutable borrow on `resources`, then updates the `resource` signal—which re-runs the effect that reads from the signals, which tries to immutably access `resources` and panics. It's the nested update here which causes a problem, because the inner update triggers and effect that tries to read both signals while the outer is still updating.
-You can fix this fairly easily by using the [`Scope::batch()`](https://docs.rs/leptos/latest/leptos/struct.Scope.html#method.batch) method:
+You can fix this fairly easily by using the [`batch()`](https://docs.rs/leptos/latest/leptos/fn.batch.html) method:
```rust
let update = move |id: usize| {
- cx.batch(move || {
+ batch(move || {
resources.update(|resources| {
resources
.entry(id)
- .or_insert_with(|| create_rw_signal(cx, 0))
+ .or_insert_with(|| create_rw_signal(0))
.update(|amount| *amount += 1)
})
});
@@ -83,11 +83,11 @@ Many DOM attributes can be updated either by setting an attribute on the DOM nod
This means that in practice, attributes like `value` or `checked` on an `` element only update the _default_ value for the ``. If you want to reactively update the value, you should use `prop:value` instead to set the `value` property.
```rust
-let (a, set_a) = create_signal(cx, "Starting value".to_string());
+let (a, set_a) = create_signal("Starting value".to_string());
let on_input = move |ev| set_a(event_target_value(&ev));
view! {
- cx,
+
// ❌ reactivity doesn't work as expected: typing only updates the default
// of each input, so if you start typing in the second input, it won't
// update the first one
@@ -97,11 +97,11 @@ view! {
```
```rust
-let (a, set_a) = create_signal(cx, "Starting value".to_string());
+let (a, set_a) = create_signal("Starting value".to_string());
let on_input = move |ev| set_a(event_target_value(&ev));
view! {
- cx,
+
// ✅ works as intended by setting the value *property*
diff --git a/docs/book/src/02_getting_started.md b/docs/book/src/02_getting_started.md
index 34f37fd8c..3958c6467 100644
--- a/docs/book/src/02_getting_started.md
+++ b/docs/book/src/02_getting_started.md
@@ -27,6 +27,7 @@ cargo add leptos --features=csr,nightly
```
Or you can leave off `nightly` if you're using stable Rust
+
```bash
cargo add leptos --features=csr
```
@@ -64,7 +65,7 @@ And add a simple “Hello, world!” to your `main.rs`
use leptos::*;
fn main() {
- mount_to_body(|cx| view! { cx, "Hello, world!"
}) + mount_to_body(|| view! {"Hello, world!"
}) } ``` diff --git a/docs/book/src/15_global_state.md b/docs/book/src/15_global_state.md index e17845a21..5fa73f655 100644 --- a/docs/book/src/15_global_state.md +++ b/docs/book/src/15_global_state.md @@ -29,15 +29,15 @@ all its children and descendants using `provide_context`. ```rust #[component] -fn App(cx: Scope) -> impl IntoView { +fn App() -> impl IntoView { // here we create a signal in the root that can be consumed // anywhere in the app. - let (count, set_count) = create_signal(cx, 0); + let (count, set_count) = create_signal(0); // we'll pass the setter to specific components, // but provide the count itself to the whole app via context - provide_context(cx, count); + provide_context(count); - view! { cx, + view! { // SetterButton is allowed to modify the count{move || state.with(|state| state.name.clone())}
} @@ -143,12 +143,12 @@ Here, instead of reading from the state signal directly, we create “slices” ```rust /// A component that updates the count in the global state. #[component] -fn GlobalStateCounter(cx: Scope) -> impl IntoView { - let state = expect_context::