-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feature request: custom event modifier #3193
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
Comments
This sort of thing can be achieved like so: https://svelte.dev/repl/a2431204cba841a0967900fb15c23e2c?version=3.6.4 <div on:mousemove={throttle(handleMousemove, 200)}> |
I see. missed that handler may be an expression too. |
Although we can already achieve this but I will still prefer to support passing custom functions. This will allow us to share common logic between multiple handlers without focusing too much into it and also in other situation if we want to support another new official modifier it will not necessarily require a new compiler change. For example let say you want to use keyboard shortcuts instead of doing ugly parenthesis |
But wouldn't using a function produce an error if the timeout triggers after the component has been unmounted? In the example Rich posted:
What if the component holding this div is unmounted? If the debouncing was integrated into the Svelte core, it could clear the timeout when the unmount happens. Another solution is using an action:
|
By now I have only one example where it could be useful: throttling and debouncing.
Also there is interesting idea on checking keycode in declarative way mentioned in #1088
Currently we can keep throttling/branching into handler but the same as
.stopPropagaion
it's not part of business logic rather details on how it's integrated. And with declarative way utilizing event modifier it looks more clear and easier to compose.Does it make sense?
The text was updated successfully, but these errors were encountered: