Skip to content

Add single listener deregistration #1969

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

Merged
merged 15 commits into from
Oct 22, 2022

Conversation

joshbuddy
Copy link
Contributor

@joshbuddy joshbuddy commented Oct 13, 2022

This provides an API to address this issue.

#1962

My one question with this change is how do you test these sorts of changes?

@joshbuddy joshbuddy force-pushed the feature/single-listener-off branch from 3a20a54 to ddbfa6c Compare October 13, 2022 16:43
Copy link
Contributor

@avengerweb avengerweb left a comment

Choose a reason for hiding this comment

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

I also worked on similar PR

eventListeners[eventName].push(thisListener);
return thisListener;
Copy link
Contributor

Choose a reason for hiding this comment

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

probably better to return "cancel" callback instead, to avoid exposing internal Listener API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the question I brought up in my issue. I can see advantages in having a more active style api, and returning the listener itself would facilitate that. Otoh, simply returning the cancel function is the 80% usecase, so I dig that simplicity.

Copy link
Member

Choose a reason for hiding this comment

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

Returning a cancel callback was the first thing I thought of too. How easy is it to manage those callbacks though? Are the 2 approaches mutually exclusive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, I think it would be better to have a design discussion on the issue instead of the PR, but happy to do it here if you're really into that.

In short, if this was my design, I would have a low level Listener interface, and then some higher level functions on top that correspond to the existing api, but with a few tweaks. I would more closely align it with nodejs's eventemitter api with a goal of it being more idiomatic js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And, I'm happy to make the changes to the api to more what I'm describing, just didn't want to actually do that unless people were into it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Returning a cancel callback was the first thing I thought of too. How easy is it to manage those callbacks though? Are the 2 approaches mutually exclusive?

I think main problem that approach with returning listener object will expose it when it is not intended to be exposed (it seems private interface with limited documentation).

@joshbuddy joshbuddy force-pushed the feature/single-listener-off branch from ddbfa6c to 598d631 Compare October 14, 2022 18:09
@joshbuddy joshbuddy force-pushed the feature/single-listener-off branch from 598d631 to a9a74e3 Compare October 14, 2022 18:10
@leaanthony
Copy link
Member

This change would need an update to runtime.d.ts too. Have you considered how the Go API should be affected by this?

@joshbuddy
Copy link
Contributor Author

I think I would not touch the go api for now, merely ship this, and then revisit the go api with an eye towards making it more go-like.

@leaanthony
Copy link
Member

I think it's important to keep the API as consistent as possible between Go and JS. I think returning a function there is also ok?

@joshbuddy joshbuddy force-pushed the feature/single-listener-off branch from 1f0fb2a to 0b745c2 Compare October 18, 2022 07:30
@leaanthony
Copy link
Member

Added a sample test for Go. Feel free to update with your own tests 👍

@joshbuddy
Copy link
Contributor Author

@leaanthony so, I haven't seen any place for js tests to go here. If there is I'll happily add them. If there isn't I'm going to hold off on adding tests to this pr, better to do it in a separate branch

@leaanthony
Copy link
Member

leaanthony commented Oct 20, 2022

I'm happy for you to add a testing framework for JS to this PR. There isn't too much to test. I think my preference would be vitest: https://vitest.dev/

@joshbuddy
Copy link
Contributor Author

@leaanthony sure, sounds good! Any thoughts on integration tests themselves? I couldn't see any work in that direction

@leaanthony
Copy link
Member

Open to ideas. If you mean between Go and JS, then yeah... Nobody is sure yet. I've been meaning to check out https://nutjs.dev/ to see if that might help.

I think we may need a "test" target that builds against a headless frontend that we can query. It's pretty tricky.

@avengerweb
Copy link
Contributor

Open to ideas. If you mean between Go and JS, then yeah... Nobody is sure yet. I've been meaning to check out https://nutjs.dev/ to see if that might help.

I think we may need a "test" target that builds against a headless frontend that we can query. It's pretty tricky.

Probably is best idea to start with unit tests for core functionality, then integration tests using browser and after that time will come to e2e tests. I did small research some time ago for my own apps; however, there is no good solution for e2e tests of webview that cover all 3 targets (Windows, MacOS, Linux). It easy for Windows and Linux as they use Chromium but MacOS will be left aside.

@joshbuddy
Copy link
Contributor Author

Sounds like writing good integrations tests is a big unknown but high value if we can make them robust. Anyhoo, lets finish off this work before figuring out stuff like that.

@leaanthony thanks for the vitest reco. Very pleasant test framework to use!

Copy link
Member

@leaanthony leaanthony left a comment

Choose a reason for hiding this comment

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

Is this still a work in progress?

@joshbuddy
Copy link
Contributor Author

@leaanthony I think this is ready

@leaanthony
Copy link
Member

leaanthony commented Oct 22, 2022

Thanks so much for taking the time to do this! A couple of minor things and I think we should be good to go:

@joshbuddy
Copy link
Contributor Author

@leaanthony how's that look?

@leaanthony
Copy link
Member

@joshbuddy - yeah cool. I think the first link wasn't updated (same filename - easy to confuse!).

@joshbuddy
Copy link
Contributor Author

@leaanthony
Copy link
Member

Oh that's so weird - I must have mistakenly been on a different branch 🤯

@leaanthony
Copy link
Member

Thanks so much for this @joshbuddy !

@leaanthony leaanthony merged commit 9f751d6 into wailsapp:master Oct 22, 2022
@joshbuddy joshbuddy deleted the feature/single-listener-off branch October 23, 2022 16:40
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.

3 participants