The event source parameter can be reactive.
In the following example, we will always subscribe on the current view (and unsubscribe from the previous one):
// model.getCurrentView() is implemented using signals consthandle = on(() =>model.getCurrentView().clicked, (event) => { console.log("Clicked at", event.x, event.y); });
Listens for events on the specified event source and invokes the
callback
for each event.The
source
parameter can be a plain event source, a signal, or a reactive function that returns the event source.on
returns a cleanup handle that should be used to stop listening for the event.Example:
The event source parameter can be reactive. In the following example, we will always subscribe on the current view (and unsubscribe from the previous one):