• 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:

    import { onSync } from "@conterra/reactivity-events";

    const view = ...;
    const handle = onSync(view.clicked, (event) => {
    console.log("Clicked at", event.x, event.y);
    });
    // Later, to clean up:
    handle.destroy();

    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
    const handle = onSync(() => model.getCurrentView().clicked, (event) => {
    console.log("Clicked at", event.x, event.y);
    });

    Type Parameters

    • T

    Parameters

    Returns CleanupHandle