• Register event listener.

    Type Parameters

    • T = unknown

    Parameters

    • target: any

      the channel object.

    • eventName: EventIdentifier | EventIdentifier[]

      event name(s)

    • listener: (value: T) => void

      event listener

    Returns EventHandle

    handle with remove method

    // object as event channel
    const channel = {};
    // connect to event "changed"
    on(channel, "changed", (msg)=> console.log(msg));

    // it is possible to register to multiple events using ','
    on(channel, "changed,click", (msg)=> console.log(msg));

    // it is possible to register to any events using '*'
    on(channel, "*", (msg)=> console.log(msg));

    // on provides handle to unregister
    const handle = on(channel, "changed", (msg)=> console.log(msg));
    // unregister using "remove"
    handle.remove();