Skip to content

docs: recommend EventHandle.off() for event removal#8974

Merged
mvaligursky merged 1 commit into
mainfrom
mv-eventhandler-off-docs
Jun 26, 2026
Merged

docs: recommend EventHandle.off() for event removal#8974
mvaligursky merged 1 commit into
mainfrom
mv-eventhandler-off-docs

Conversation

@mvaligursky

@mvaligursky mvaligursky commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

EventHandler.on() / once() return an EventHandle, and calling handle.off() removes exactly that subscription without scanning the callback list — but this advantage was documented only on the internal offByHandle() (@ignore). The public API surface only showed the string-based off(name, callback, scope), which is the universal EventEmitter idiom and dominates usage (~2:1 in this repo).

This adds guidance to the public on() / once() / off() JSDoc so the preferred removal path is discoverable:

  • on() / once() @returns now recommend retaining the handle and calling EventHandle#off, noting it removes exactly that subscription and is faster.
  • off() description now scopes the string form to bulk/by-name removal and points to the handle for removing a single known subscription.

Docs only — no runtime or signature changes.

The string-based EventHandler.off(name, callback, scope) is the universal
EventEmitter idiom and dominates usage, but the handle returned by on()/once()
removes exactly one subscription and is faster (no scan of the callback list) -
a benefit previously documented only on the internal offByHandle().

Surface that guidance on the public on()/once()/off() JSDoc so the preferred
removal path is discoverable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Build size report

This PR does not change the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2262.6 KB — 582.0 KB — 452.7 KB —
playcanvas.min.mjs 2260.0 KB — 581.1 KB — 452.1 KB —

@mvaligursky mvaligursky merged commit 5fbe2ee into main Jun 26, 2026
10 checks passed
@mvaligursky mvaligursky deleted the mv-eventhandler-off-docs branch June 26, 2026 09:50
mvaligursky added a commit that referenced this pull request Jun 26, 2026
The string-based EventHandler.off(name, callback, scope) is the universal
EventEmitter idiom and dominates usage, but the handle returned by on()/once()
removes exactly one subscription and is faster (no scan of the callback list) -
a benefit previously documented only on the internal offByHandle().

Surface that guidance on the public on()/once()/off() JSDoc so the preferred
removal path is discoverable.

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant