Skip to content

JS: Introduce helper functions for event listeners#5495

Draft
osipxd wants to merge 1 commit intorelease/3.xfrom
osipxd/typesafe-js-event
Draft

JS: Introduce helper functions for event listeners#5495
osipxd wants to merge 1 commit intorelease/3.xfrom
osipxd/typesafe-js-event

Conversation

@osipxd
Copy link
Copy Markdown
Member

@osipxd osipxd commented Mar 28, 2026

Subsystem
JS/WasmJS client

Motivation
The existing approach was error-prone: it was easy to forget to call removeEventListener for one-time listeners, and the only correct implementation required a lateinit var to hold the callback reference so it could be removed inside itself.

Solution
Introduces two internal helpers in the web source set (shared between js and wasmJs):

  • EventTarget.addEventListener<T>(vararg events, listener) — type-safe wrapper that captures the callback internally and returns a DisposableHandle, eliminating the need to keep a separate lambda reference for cleanup.
  • EventTarget.addOneTimeEventListener<T>(vararg events, listener) — registers a listener that automatically removes itself after the first matching event fires, replacing the lateinit var pattern.

Refactors JsClientEngine, WasmJsClientEngine, and JsWebSocketSession (both js and wasmJs) to use these helpers.

@osipxd osipxd self-assigned this Mar 28, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 60ef101b-e54e-4464-afd9-ca192a415385

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osipxd/typesafe-js-event

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@osipxd osipxd changed the title JS: Introduce helper functions for event listers JS: Introduce helper functions for event listeners Mar 28, 2026
@osipxd osipxd force-pushed the osipxd/typesafe-js-event branch 2 times, most recently from 0666f3b to f7a5d01 Compare March 30, 2026 23:44
@bjhham
Copy link
Copy Markdown
Contributor

bjhham commented Mar 31, 2026

Good call 👍

@osipxd osipxd force-pushed the osipxd/typesafe-js-event branch 2 times, most recently from 3f26045 to 5a9cf5a Compare March 31, 2026 10:08
@osipxd osipxd force-pushed the osipxd/typesafe-js-event branch from 5a9cf5a to 96416ea Compare March 31, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants