-
-
Notifications
You must be signed in to change notification settings - Fork 711
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
ImmediateEffect
#3650
base: main
Are you sure you want to change the base?
ImmediateEffect
#3650
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you! This would close #2822.
I have looked over the implementation and it certainly looks correct to me. The only thing missing is adding some tests -- my assumption would be that copying some of the tests in tests/effects.rs
, using immediate effects, and dropping the various Executor::tick().await;
points (which wait for the current, batched/async effects to run) would be sufficient to test this!
Really nice work, and much appreciated.
(Oh, and just to add a note on the Send/Sync bounds: these are okay, and definitely a requirement. I'd say that for this niche use case, I'm perfectly happy to say that users who need to run them on the current thread are very likely doing so in a single-threaded browser context and can use |
ffed37a
to
f7a1a2c
Compare
Definitely! I wanted to get it up as soon as possible to avoid doing this in the dark. So, some more design considerations:
I think I am leaning toward 'allow recursion', no |
The goal here is to make the behavior under recursion better defined.
Implemented it as described above, I'll probably give it a look over the weekend with fresh eyes. It'll also need some multi-threaded tests. |
This introduces
ImmediateEffect
, which executes its effect once upon creation and then every time a dependency changes, immediately.This is not what you want in most code, but is useful for some kinds of double-binding (for example to some syncing mechanism like CRDTs, or a signal to the browser's route state).
I think this can live outside
leptos
, so if you think it's better to keep it out or this version is not quite where you want it, I am happy to close this.A note on
Send
andSync
: since the dependency that triggers the effect could be in any thread, this also means the effect always has to beSend
andSync
. I still matched theEffect
interface.This is unfortunate, but I couldn't figure out a way to avoid that without
unsafe
, and even then it would have 'solved' the problem by panicking if called from another thread.I left that code in an intermediate commit, but as there is currently no
unsafe
code inleptos
, I don't think it's worth it even if it's sound (as a casual observer would lose the simple and strong no-unsafe anywhere guarantee).cc: #2822