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

Calling alt.off with invalid function reference breaks other listeners #229

Open
1 task done
xxshady opened this issue Nov 25, 2022 · 1 comment · Fixed by #234
Open
1 task done

Calling alt.off with invalid function reference breaks other listeners #229

xxshady opened this issue Nov 25, 2022 · 1 comment · Fixed by #234
Assignees
Labels
type: bug Something isn't working

Comments

@xxshady
Copy link
Contributor

xxshady commented Nov 25, 2022

Description of the problem

See reproduction code.

Reproduction steps

const handler = (key) => {
  alt.log("keydown", key)
  listenKeydown()
}

const listenKeydown = () => {
  const [listener] = alt.getEventListeners("keydown")
  alt.log("keydown listener:", listener)

  if (listener) {
    alt.log("alt.off keydown with invalid function ref")
    alt.off("keydown", () => {})
  } else {
    alt.log("alt.on keydown")
    alt.on("keydown", handler)
  }
}

listenKeydown()

Expected behaviour

Maybe we should check if passed function reference is not valid and throw error?

Additional context

No response

Operating system

Windows 11

Version

13.0-rc2

Scope

shared

Reproduction tested

  • I confirm that I have made sure that this issue is also present on the newest dev version
@LeonMrBonnie
Copy link
Contributor

The PR didn't actually fix it, so I will leave it open for now until we actually fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants