Composables

useGlobalEvent

Source
Subscribe to a Lynx GlobalEventEmitter event — native-to-JS signals from the host app — with automatic cleanup.

Overview

GlobalEventEmitter is the background-thread channel for native → JS events: Lynx's own (keyboardstatuschanged, exposure), and anything your host app sends with sendGlobalEvent. useGlobalEvent wraps the subscription with component lifecycle — attached in onMounted, detached in onUnmounted:

<script setup lang="ts">
import { useGlobalEvent } from '@vyui/core'

useGlobalEvent('connectivitychanged', (...args) => {
  const online = args[0] === 'online'
  // ...
})
</script>

Listeners receive the event's variadic args verbatim — cast to the payload your host sends. On web / vitest there is no lynx global and the call degrades to a no-op, so components stay portable and mountable without mocks.

Vy UI uses this channel itself: keyboard awareness (keyboardstatuschanged), lazy mounting (exposure / disexposure), and live theme changes (themechanged — see useColorMode). The native host integration guide shows the sending side.

Signature

useGlobalEvent(name: string, listener: (...args: unknown[]) => void, options?: UseGlobalEventOptions): void

  • name — the global event name.
  • listener — receives the event's args verbatim.
  • options.immediate — subscribe synchronously during setup() instead of onMounted, for events that can fire before mount (Lynx can emit exposure for views in the initial layout). Defaults to false.

Call during setup().