useGlobalEvent
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 duringsetup()instead ofonMounted, for events that can fire before mount (Lynx can emitexposurefor views in the initial layout). Defaults tofalse.
Call during setup().