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

feat(core): allow unregistering callback through on #11710

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Commits on Apr 28, 2024

  1. feat(core): allow unregistering callback through on

    This commit updates the return signature of the client's `on` function to be a void function,
    which, when executed, unregisters a callback. This adjustment is necessary for managing instances
    where objects are created and destroyed, ensuring that callbacks are properly unregistered to
    prevent self-referencing in callback closures and facilitate proper garbage collection.
    
    Typically, changing a type from `void` to `() => void` (or `VoidFunction`) shouldn't be considered
    a breaking change because `void` signifies the absence of a return value, implying that the return
    value of the `on` function should never be used by consumers.
    
    Opting for the `on` approach, which returns a cleanup function, "seems" simpler because having another
    function called `off` requires saving the callback reference for later removal. With our pattern,
    we encapsulate both the registration and removal of event listeners within a single function call.
    arturovt committed Apr 28, 2024
    Configuration menu
    Copy the full SHA
    5a2041b View commit details
    Browse the repository at this point in the history