Comments (6)
Note also that I've resisted this for .update()
on signals, because of the fact that event handlers require a function that returns ()
. Returning something from .update()
means that on:click=move |_| count.update(|n| *n += 1)
would need to be rewritten across the board to on:click=move |_| { count.update(|n| *n += 1); }
, which is worse IMO.
We previously had an .update_returning()
, which was deprecated and merged into .try_update()
I would actually suggest that
// note the change to .flatten()
if let Some(v) = stored.try_update_value(|v| v.take()).flatten() {
// do something with v
}
is the best solution here, as it won't panic.
from leptos.
Returning something from
.update()
means thaton:click=move |_| count.update(|n| *n += 1)
would need to be rewritten across the board toon:click=move |_| { count.update(|n| *n += 1); }
, which is worse IMO.
I don't think this is true. In my little test:
fn my_update<O>(f: impl FnOnce(&mut i32) -> O) -> O {
todo!()
}
let _ = view! {
<div on:click=move |_| my_update(move |v| *v += 1) />
};
compiled with no problems. I think fn() -> ()
and fn()
are identical.
from leptos.
Sorry, I'm talking about the version that returns an Option. .update() currently does not panic if you update a signal that has been disposed. .update_value() does and that should probably be changed. I will not change .update() on signals to panic if disposed and return a value.
from leptos.
Since it seems the idiomatic use case would be to always use try_update
in every scenario, what is the use case for update
then? And why doesn't the same apply to with
which does return the inner value? I think that's rather inconsistent and definitely counter intuitive.
from leptos.
And why doesn't the same apply to
with
which does return the inner value?
The goal of the design decisions here is minimize panicking while making the most-common case the default one. .with()
must return a value, or it's meaningless, so it defaults to panicking if disposed, and you can opt into .try_with()
if that might be the case. .update()
does not need to return a value in the overwhelming majority of cases, so it defaults to not panicking, and you can opt into .try_update()
if you want the return value.
Unless I'm mistaken you're suggesting changing the behavior of .update()
so that it is essentially .try_update().unwrap()
, right? This will increase the likelihood of panicking, which is bad because panics are unrecoverable in WASM.
Since it seems the idiomatic use case would be to always use
try_update
in every scenario, what is the use case forupdate
then?
I don't understand what you mean here, sorry.
from leptos.
ok, I think I understand the issue with this. Somehow I was under the impression that the callback was called every time, but ofc it makes sense that it's not being called when the signal is disposed.
from leptos.
Related Issues (20)
- create_resource inside Suspense causes server panic HOT 3
- session_auth_axum example doesn't build
- `wasm_bindgen` assumed to exist with `#[island]` HOT 3
- Suspense does not work with conditionally accessed resources HOT 2
- Server action's value is None after calling the action with JS/WASM disabled HOT 6
- tailwind_axum example css is not loaded HOT 1
- Server action's error value is not picked up after calling the action with JS/WASM disabled HOT 7
- Feature Request: Support functions that can run on the client in ActionForm HOT 2
- tailwind_csr example css is not loaded.
- Cancelling a timeout or animation frame request leaks the associated closure
- Nested suspense hydration errors (Islands)
- server fn call fails with empty `HashSet` HOT 3
- `<!DOCTYPE html>` tag is never rendered HOT 1
- Resource and timouts lacks any cancelation HOT 2
- Context missing in server function called from router fallback during SSR HOT 3
- ci(examples): build hackernews_js_fetch with deno
- relocation of nestedly imported js in wasm_bindgen HOT 3
- SSR renders in the wrong order HOT 4
- Route component without re-render its view HOT 2
- Add a method to create derived signals based on an `Option<T>` signal HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leptos.