Replies: 1 comment 7 replies
-
|
Is there any reason to use a Otherwise, adding an event listener is an effect, so calling an Effect to read from the LocalResource and check whether it's Some is reasonable. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm having a bit of a hard time wrapping my head around how signals and resources are supposed to interact.
I'm trying to build a simple media player based on
web_sys::HtmlAudioElementandweb_sys::AudioContext. Setting up the context takes a bit of boilerplate, so I factored that out into a separate struct; since all of this can only run on the client it all goes into aLocalResource. So far so good:Now, however, I want to listen to
errorevents on theHtmlAudioElement(or really, any event,erroris just easy to test by pointing the source at a nonexistent file).leptos_usefeatures theuse_event_listenerfunction, which AIUI should create a signal that does that if I can provide it the correct inputs. This is where I get stuck - I don't understand how I'm supposed to hand this a signal that is not aTto this function.I've attempted this:
But this doesn't compile - it doesn't look like derived signals implement the necessary trait (nor do
Memos, FWIW):help: the trait `IntoElementMaybeSignalType<EventTarget, _>` is not implemented for closureDoing this in an Effect works just fine, and is sufficient to get the log to show up, but that's not what I want to ultimately accomplish here:
I have a feeling I'm going completely in the wrong direction here, but I don't even know where to begin looking for an alternative approach. I suppose I could implement these things with just
web_sys, but then the state machine moves outside the scope of leptos and propagating events to the UI becomes cumbersome.Anyone mind clearing up my confusion?
Beta Was this translation helpful? Give feedback.
All reactions