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

Merged
merged 3 commits into from
Jul 4, 2024

Commits on Jul 4, 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 authored and mydea committed Jul 4, 2024
    Configuration menu
    Copy the full SHA
    2c38627 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cf9e279 View commit details
    Browse the repository at this point in the history
  3. fix it, oops...

    mydea committed Jul 4, 2024
    Configuration menu
    Copy the full SHA
    d7c2fd4 View commit details
    Browse the repository at this point in the history