Listens for events on the specified event source and invokes the callback for each event.
This function is the synchronous variant of on.
Event callbacks will be invoked without delay after events have been emitted.
The source parameter can be a plain event source, a signal, or a reactive function that returns the event source.
onSync returns a cleanup handle that should be used to stop listening for the event.
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 = onSync(() =>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. This function is the synchronous variant of on. Event callbacks will be invoked without delay after events have been emitted.The
source
parameter can be a plain event source, a signal, or a reactive function that returns the event source.onSync
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):