@alwaysblank/denden
    Preparing search index...

    Function watch

    • Watch an event emitter and retransmit events to a channel.

      Type Parameters

      • Payload

        The type of the payload carried by the message(s) being published.

      Parameters

      • hub: Hub

        Hub to which watched events will be dispatched.

      • channel: ChannelRoute | ChannelRoute[]

        The name of the channel(s) to dispatch to. Will create fully qualified routes if they do not already exist.

      • target: EventTarget

        EventTarget to watch for events of eventType.

      • eventType: string

        Type of event to watch for on target.

      • Optionalprocessor: WatchProcessor<Payload>

        Callback to convert events from target into the appropriate payload for channel. Defaults to simply returning the entire event object.

      Returns () => void

      const hub = new Hub();

      watch(hub, 'sandwiches', window, 'sandwich');

      hub.sub('sandwiches', (p) => console.log(`received: ${p.detail}`));
      window.dispatchEvent(new CustomEvent('sandwich', {detail: 'reuben'}));
      // "received: reuben"