Function eventListener

  • Composes a listener function from the functions in ops. ops may be a single function or an array of functions.

    The functions are called in the same order when handling events. They will receive as erguments the event object and a run context.

    The run context can be passed as the second argument to this function (or it will default to the global runContext). The context can be used for communication and it also maintains a running property which will ensure that no 2 handlers using it will run concurrently (providing the API is respected).

    The API is as follows: If a handler function returns a promise, it is assumed to still be running until the promise resolves or rejects. Neither the handler nor any other handlers using the same run context can start until it stops running.

    Individual op functions can also terminate event handling by returning the END symbol.

    Parameters

    • ops: Function | Function[]

      The function or functions making up the handler

    • Optional runContext: any

      The optional run context.

    Returns ((e) => any)

      • (e): any
      • Parameters

        • e: any

        Returns any

    Example

    import { eventListener, onEnter } from 'deleight/eutility';
    input.onkeyup = eventListener([onEnter, () => login(input.value), preventDefault]);
    apply({
    '#loginButton': button => {
    button.onclick = eventListener(() => login(input.value));
    }
    }, form);