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 duplicate serial console messages #243

Merged
merged 5 commits into from
Aug 28, 2024

Conversation

FoamyGuy
Copy link

Resolves #234

I am not positive, but I think the existing removeEventListener() is not working because this.onSerialReceive.bind(this) is producing a new function each time it's called. So when it gets called for remove() technically it is a different instance of the function than the one that ends up being passed to addEventListener() and thus the one that will need to be passed next time to remove in order for it to get de-activated.

This resolves it by creating the callback once, storing it on this and then referencing it from there for both the add and remove listener calls.

I tested this locally and it does seem to resolve the duplicate serial issue, with it I can now disconnect / re-connect multiple times and still end up with just a single instance of the serial output.

@FoamyGuy FoamyGuy changed the title save messageCallback on this, and remove listener on it Fix duplicate serial console messages Aug 28, 2024
Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

Thanks for the change. Let's make it private, so let's rename it to this._messageCallback. Also, please add to the constructor.

js/workflows/usb.js Outdated Show resolved Hide resolved
@makermelissa
Copy link
Collaborator

Updated my comment as using "Callback" was consistent with other usages.

@FoamyGuy
Copy link
Author

Thank you, It's been renamed, and added to the constructor with latest commits.

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

Thanks

@makermelissa makermelissa merged commit aeb886c into circuitpython:beta Aug 28, 2024
1 check passed
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.

2 participants