Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overwrite EventBus.off method to clear once events #13736

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Antreesy
Copy link
Contributor

@Antreesy Antreesy commented Nov 8, 2024

☑️ Resolves

  • Fix stray once event listeners, if they were never called

🖌️ UI Checklist

🏁 Checklist

  • 🌏 Tested with different browsers / clients:
    • Chromium (Chrome / Edge / Opera / Brave)
    • Firefox
    • Safari
    • Talk Desktop
    • Not risky to browser differences / client
  • ⛑️ Tests are included or not possible

Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fun of adding a new function to unsubscribe from a listener. Unlisten shouldn't be different between on and once. It has the same semantics and job. Same for other Event Emitters, including native removeEventListener.

Also, identifying a function by name is not reliable. It can be empty, it can be not unique.

Instead, let's store once handlers in a Map<type, Map<originalHandler, onceHandlers>> and override off method to support new feature.

@Antreesy Antreesy force-pushed the fix/noid/event-bus-once-garbage branch from a13e2ca to 1ca78af Compare November 8, 2024 18:38
@Antreesy Antreesy changed the title feat: introduce EventBus.cancelOnce to clear once events fix: overwrite EventBus.off method to clear once events Nov 8, 2024
@Antreesy Antreesy requested a review from ShGKme November 8, 2024 18:38
src/services/EventBus.ts Outdated Show resolved Hide resolved
src/services/EventBus.ts Outdated Show resolved Hide resolved
src/services/EventBus.ts Outdated Show resolved Hide resolved
Signed-off-by: Maksim Sukharev <[email protected]>
Signed-off-by: Maksim Sukharev <[email protected]>
Signed-off-by: Maksim Sukharev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants