r/javascript • u/Forward_Dark_7305 • Aug 17 '26
AskJS [AskJS] Signal/Effect vs Event Handler
I’m working in a VanillaJS repository (plugin type code for an existing project that I do not own) where I’ve written a signal implementation.
Today I was working on a tooltip like implementation and I found myself wondering how far to go with the signal/effect ecosystem vs running the “core” logic in the event handler.
The implementation detects the `<tr>` that the user has hovered and assigns that row to the “current row” signal. A computed signal identifies an IP address from the current row. An effect loads Whois metadata from the IP and assigns it to a `<div>`, and another effect shows that `<div popover>` from the parent `<tr>`.
The question I have is when in VanillaJS how would you decide when to use signals and effects vs writing the side effect directly in the event handler? In my case I find either to be equally readable, though I have less local variables to deal with when using signal/effect. Looking for reasons your might pick one over the other.
View all comments
Show parent comment
3
u/Bogus_dogus Aug 18 '26
I guess the question for me just becomes like...
okay so you have a table with a sizeable number of elements...
There is some additional external data that you'd like to display which is element-specific. Each element presumably has it's own instance of that data. The table is pre-rendered without that data.
So the question becomes when to fetch which sets of supplemental data, which would defensibly fall into one of a handful of buckets:
My intuition is that it requires more complexity to handle this route of signals and computed properties than the value they bring, particularly if the supplemental data can be batched at page load once you have the table data.
I don't know what API you have available for the whois lookup, but I'd ideally look for an API which supports batch requests for something like this; there is already a window of non interactivity built in where the runtime of the batch request can be masked. If I were designing an API like this I would probably prefer my consumers to make one batch request for 100 items rather than 100 individual requests. Much nicer on my backend. And as a user, I would imagine the experience is probably nicer to face one load period during the existing page-load window where the 200 items are prefetching their supplemental data... then the popup just has 1 piece of loading state to track which resolves early and once, followed by a single keyed lookup for that row's whois payload, meaning no more loading spinners...
I can't say I really see the value in complicating it any further. I don't imagine that a 200 entity lookup batch would be all that much longer than a single entity lookup batch against a quality API, the loading timing is better from a UX perspective if it's immediately following page hydration for all rows rather than deferred 'til a proxy signal for user interest, and most of the intermediate complexity is serving potentially undesired information needs based off an imperfect proxy signal that fires at a rapid rate and needs extra tooling to support proper abort signals and/or debouncing, on top of probably frequent bursty web requests to whatever API you're consuming