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

adds removeHostListeners #14

Merged
merged 4 commits into from
Jun 15, 2020
Merged

adds removeHostListeners #14

merged 4 commits into from
Jun 15, 2020

Conversation

stardisblue
Copy link
Contributor

@stardisblue stardisblue commented Jun 14, 2020

Gives the ability de remove all the event listeners, this should only be used when throwing away the EasyPZ instance. *(see note)

Event functions (e.g.: onMouseUp) were changed to preserve the this binding, that way, they can be passed directly in addEventListener and removeEventListener.

note :

We could set setupHostListenersto public to allow EasyPZ to reattach. But EasyPZ preserves transformations, so it might create undesired side-effects if the transformation was affected by another party.

Maybe I will put another pull request to reset all EasyPZ tranformations, which might satisfy a lot of cases.

Other :
Equivalent working example : https://observablehq.com/@stardisblue/hello-easypz

fixes #13

stardisblue and others added 4 commits June 14, 2020 13:44
Event function were changed to preserve `this` binding, that way, the reference can be passed directly for addEventListener and removeEventListener.
@michaschwab
Copy link
Owner

Thanks for your contribution! I didn't like turning the methods into anonymous functions, so I changed it slightly to instead use bound functions before assigning and removing the listeners, but no substantial change.
Can you please take a look to see if it still works the way you want after my changes? If so, I'll merge your PR!

@stardisblue
Copy link
Contributor Author

My method was at first glance less verbose, but i found that it causes problems when extending (ref: https://stackoverflow.com/a/45882417).
I don't see any problems with this method. 🎉

@michaschwab michaschwab merged commit 2b7c9fb into michaschwab:master Jun 15, 2020
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.

Programmatically detach EasyPZ
2 participants