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, attaching in onMounted and detaching 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, so 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). Sparkling handles the sending side for most apps; if you need to build a custom host, see native host integration guide for platform code.
Signature
useGlobalEvent(name: string, listener: (...args: unknown[]) => void, options?: UseGlobalEventOptions): void
nameis the global event name.listenerreceives the event's args verbatim.options.immediatesubscribes synchronously duringsetup()instead ofonMounted, for events that can fire before mount (Lynx can emitexposurefor views in the initial layout). Defaults tofalse.
Call during setup().