Replies: 9 comments 1 reply
-
I believe it should be possible somehow without the following workaround (based on expectations people have with how templating works): <div onclick={() => handler()()}>click me</div> |
Beta Was this translation helpful? Give feedback.
-
Yeah I've never supported this. Mostly because it adds a lot of complications and I have always felt the workaround was more or less fine. Now that I have better heuristics it seems reasonable to revisit.. one problem is the case when someone writes: <div onclick={handlerSignal}>click me</div> Like it's not going to work the way you think.. on Click sees it is a function and will be like that's the handler. I mean that is fine generally though since everything else works like that. It's also awkward with binding syntax (which I need to double check works at only compile time). The other more annoying problem for me is: <div onclick={props.onClick}>click me</div> Since this is pretty common pattern and it would always have to be dynamic. Potentially an extra computation per row. Although that dynamicism is probably expected. Of course there is a work around for that too: <div onclick={e => props.onClick(e)}>click me</div> Maybe that is really the best work around.. What if your handler example basically compiled into <div onclick={e => handle()(e)}>click me</div> We probably need to handle the null case.. but more or less that.. that way no extra computation, no event rebinding. Something like this: e => {
let h;
(h = **expr**) && h(e);
} |
Beta Was this translation helpful? Give feedback.
-
It does occur to me that this only works for JSX compilation. For like |
Beta Was this translation helpful? Give feedback.
-
Maybe an opt-in namespace like |
Beta Was this translation helpful? Give feedback.
-
namespace name ideas: <div sig:onclick={getOnClick}>click me</div>
<div sign:onclick={getOnClick}>click me</div>
<div signal:onclick={getOnClick}>click me</div>
<div read:onclick={getOnClick}>click me</div>
<div bind:onclick={getOnClick}>click me</div>
<div wire:onclick={getOnClick}>click me</div>
<div hook:onclick={getOnClick}>click me</div>
<div hookup:onclick={getOnClick}>click me</div>
<div connect:onclick={getOnClick}>click me</div>
<div react:onclick={getOnClick}>click me</div>
<div reactive:onclick={getOnClick}>click me</div>
<div comp:onclick={getOnClick}>click me</div>
<div compute:onclick={getOnClick}>click me</div>
<div dyn:onclick={getOnClick}>click me</div>
<div dynamic:onclick={getOnClick}>click me</div> where whatever the name is, it basically opts into the passed-in thing being a signal for any case where it is not treated as a signal by default (like with |
Beta Was this translation helpful? Give feedback.
-
Ironically this was one of my arguments against remove The problem is this really only applies to events and it's such an edge case. This is one of those cases where I'd point at So my feeling for this one is going to be an edge case for the time being. I definitely think JSX transform is worth considering since it is consistent with the heuristics we use elsewhere so it seems reasonable. But I think non-compiled we need to wait before making any binding decisions. |
Beta Was this translation helpful? Give feedback.
-
I remember putting something together when playing with S.js/stage0. Seemed to work, but needed more thorough testing that I never got to. In JSX it'd probably look like:
Behind the |
Beta Was this translation helpful? Give feedback.
-
The main challenge here is like S.js I take a stance of signals not being special. Just thunks so when you pass it to an event it doesn't know whether it's the event handler or a dynamic signal that has the event handler. I assume with |
Beta Was this translation helpful? Give feedback.
-
The on-helper with optional synthetic events checking for / evaluating signals should work then, without needing to be in the core framework. I'll try to build something to get a better idea of how it feels. |
Beta Was this translation helpful? Give feedback.
-
For example,
The output is always
"one"
on click, even after two seconds.Beta Was this translation helpful? Give feedback.
All reactions