-
-
Notifications
You must be signed in to change notification settings - Fork 795
Resupport From<Fn() -> T> for Signal<T>
, ArcSignal<T>
, Callback<T, _>
and similar
#4273
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
base: main
Are you sure you want to change the base?
Conversation
So my first reaction was Woah and my second was How? so you've got a pretty interesting PR there. I'd love to not have to manually derive signals. Does the addition of generics on the generated into functions affect compile times at all? |
I haven't tested, I would assume non-zero, but also that it wouldn't be meaningful, I'm not actually asking the compiler for much here, it's an |
I expect it to be minimal as well, just curious. |
I've made it robust and not specific to signals, I've added support for This required me to move the callback module into |
The semver CI failing is a false positive I believe, it doesn't understand the old I'm happy with this PR now I think, it's just blocked by the upstream PR: |
From<Fn() -> T> for Signal<T>
, ArcSignal<T>
, Callback<T, _>
and similar
55d261e
to
50060d6
Compare
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.
... Wow! 😍 This is really great. Honestly kind of mindblowing.
I understand why using a marker generic lets us get around the conflicting trait implementations (they are no longer conflicting.)
I'm a little worried about the potential for this to break in subtle ways where the compiler can't infer the type of the marker. (I haven't thought it through that fully, or found cases where it does break -- I'm just used to the compiler enough to anticipate it! 😄)
My only comment other than the individual nits is a bikeshedding one about the name: if we're putting it in the non-leptos-specific reactive_graph
trait perhaps IntoReactiveValue
or something rather than IntoLeptosValue
?
In any case, awesome work and an ingenious solution.
😅 I haven't been able to find a valid case it fails yet, as long as the I'd encourage you to try and break it though!
Very happy to change it, but I don't think |
978f582
to
8616231
Compare
Not sure I like IntoLeptosValue either, not really clear what a LeptosValue is 😛 |
We're actually using the same kind of trick with |
Thanks @maccesch. There were a few places I came across inference issues with the For example: #[component]
fn App() -> impl IntoView {
Effect::new(move |prev| {
if prev.is_some() {
log!("not the first run");
}
log!("foo bar {prev:?}");
});
} compiled on 0.6, but on 0.7/0.8 it yields the error
(The changes to Effect are still a net win, in my opinion, to be clear!) It's possible that this kind of inference error doesn't apply here because the component prop type needs to be provided. I haven't fully though through how the two implementations parallel each other... (and I'm going to log off for the evening instead!) |
Understood. Excited to see where you land on this. |
8616231
to
97259a6
Compare
Should be good to go now other than any bikeshedding on As mentioned before the failed semver CI check is a false positive. |
I think the failed semver check is due to moving callback module from |
06443b8
to
279abd3
Compare
I guess I'm okay with just disabling this on nightly, although it raises a moderately large issue: namely that it would prevent us from stabilizing the function-call syntax once the relevant nightly traits are stabilized without removing this implementation again (which would be a breaking change). I may be having trouble remembering the history here. Was the situation in 0.6 that In any case I am sure that merging this is the right idea -- I will just wait for the CI to finish running. |
Oh and re: bikeshedding — are you okay with |
I'm okay with anything, although I'd hesitate that
It's a good question, I'm unsure too and could check deeper next week but a quick check back in the git history seems like it might have been a 0.8 feature (61f5294, 1f2b13a)? Either way I think the standardisation to this PR in a 0.9 for nightly also, rather than keeping the nightly |
I checked this out, and it did support both by utilising |
f617c7f
to
13bba18
Compare
Rough draft to enablesupport for reactive closures to auto convert toSignal
, without having to remove theFrom<T>
implementation.Requires a tweak to
typed-builder
hereWe can break the "conflicting implementations" issue with a marker (
M
) struct on anIntoSignal<T, M>
trait.which can instead be written as:
This means we need an
<M>
generic on the builder method generated bytyped-builder
, which already supports calling a custom "transformer", just not with generics, hence the new transform_generics config I added here.This in
leptos_macro
becomes in the case ofSignal<usize>
:This works!!
This can be extended to support other types,
ReadSignal
,Callback
etc where needed too