global-events

command
v4.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 3 Imported by: 0

README

Global Events

A child component owns a document-level keydown listener and increments a counter that lives in the parent — so the count survives the child's unmount/remount and proves the listener is cleaned up.

What it shows

  • ui.UseGlobalKey(fn) — a managed document keydown listener whose underlying js.Func lifetime is scoped to the effect (registered on mount, released on unmount).
  • Lifting the counter into the parent so toggling the child off and on cannot reset it.
  • Leak-safety: if the listener weren't released on unmount, a single keypress after remount would double-count. It doesn't.

Run

gwc dev examples/public/global-events

Press a key to increment; toggle the listener child off and on and confirm a keypress still counts exactly once.

Documentation

Rendered for js/wasm

Overview

Command global-events is the e2e fixture for G9 (ui.UseGlobalKey): a child component owns a document-level keydown listener and increments a counter that lives in the parent (so it survives the child's unmount/remount). This lets the e2e prove both that the listener fires and that it is cleaned up on unmount — if the js.Func leaked, a single keypress after remount would double-count.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL