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

Use EventTarget rather than the Node "events" module #1188

Merged
merged 6 commits into from
Jul 9, 2024

Conversation

microbit-matt-hillsdon
Copy link
Collaborator

@microbit-matt-hillsdon microbit-matt-hillsdon commented Jul 8, 2024

This should amount no meaningful change but is a useful preliminary to extracting the device code for reuse.

Incorporates the only meaningful file from https://github.com/DerZade/typescript-event-target/ (with licence details) to save on the dependency.

Compiles but untried
Forces us to remove the clean up in dispose so perhaps some kind of
assertion should replace it.
Copy link

github-actions bot commented Jul 8, 2024

@microbit-matt-hillsdon microbit-matt-hillsdon changed the title [DO NOT MERGE] Try another approach to typing event target Use EventTarget rather than the Node "events" module Jul 8, 2024

const buttonTest =
"from microbit import *\nwhile True:\nif button_a.was_pressed():\ndisplay.show(Image.NO)";
const buttonTest = `from microbit import *
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've corrected the indentation in these tests which surprised me when I saw them in failure screenshots (for reasons unrelated to the indentation).

const setSelectedFile = useCallback(
(file: string) => {
setSelection({ file, location: { line: undefined } });
},
[setSelection]
);
useEffect(() => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this was a listener ordering thing. I've changed it to avoid making a state update at all.

@@ -49,9 +50,7 @@ export class MockDeviceConnection

async initialize(): Promise<void> {}

dispose() {
this.removeAllListeners();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't do this anymore as EventTarget doesn't have such API.

All listener add/removes are correctly paired except that in host.ts and a test, neither of which need to remove their listeners.

Copy link
Collaborator

@microbit-robert microbit-robert left a comment

Choose a reason for hiding this comment

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

LGTM.

@microbit-matt-hillsdon microbit-matt-hillsdon merged commit 506446c into main Jul 9, 2024
1 check passed
@microbit-matt-hillsdon microbit-matt-hillsdon deleted the typed-event-target branch July 9, 2024 16:38
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