Events
KVision allows you to listen to all the standard DOM events and also many custom events from many different components. You bind to an event with the setEventListener
method of the base Widget
class.
Some components define a shortcut method onClick
for the click event, so you can write:
Event function parameter is not required if not used.
You can bind many different event handlers with one call to the setEventListener
method.
Unfortunately, due to internal Snabbdom implementation, you can't bind two or more handlers to the same event - the latter handler will overwrite the prior one.
Self reference inside an event handler
In the code of a basic event handler you can get the reference to the component instance with a special self
variable.
The type of the self
variable is Widget
in the above example. If you want to call a dedicated method of a receiver component you can call setEventListener
with the correct type parameter.
Last updated