Add $dispatch.once in Alpine.js #3943
Replies: 2 comments 1 reply
-
Unless you mean something different. |
Beta Was this translation helpful? Give feedback.
-
@SimoTod Probably the use case I'm exploring might be too specific. I'll work on a custom solution for this myself |
Beta Was this translation helpful? Give feedback.
-
Description:
Currently, we dispatch events using
$dispatch
. However, there are situations where we want an event to be caught only once, similar to the{ once: true }
option in JavaScript's nativeaddEventListener
.Proposal:
I suggest adding a new method or option, perhaps named
$dispatch.once
, that allows us to dispatch an event that will be caught only once. This would provide a convenient way to handle scenarios where we need to perform a specific action on the first occurrence of an event and then detach the listener.Example Usage:
Beta Was this translation helpful? Give feedback.
All reactions