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

feat: allow setting key, touch and mouse event handlers #7

Merged
merged 8 commits into from
Jun 4, 2019

Conversation

n1ru4l
Copy link
Contributor

@n1ru4l n1ru4l commented May 26, 2019

The project I am working on requires adding event listeners to the PanZoom component.

Ideally, this project would use prop getters (https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters). However, this is something to consider for a major release/braking change.

This implementation uses a list of allowed event property names in order to apply them from either the component instance methods or the props passed to the component instance.

@n1ru4l
Copy link
Contributor Author

n1ru4l commented May 27, 2019

Edit: I think I have to change this, I did not see the event listeners that were added to the document

@mnogueron Could you please explain why you choose to add the event listeners for mousedown ad mouseup to the document instead of adding those via the props?

setMouseListeners = () => {
document.addEventListener('mousemove', this.onMouseMove)
document.addEventListener('mouseup', this.onMouseUp)
}
cleanMouseListeners = () => {
document.removeEventListener('mousemove', this.onMouseMove)
document.removeEventListener('mouseup', this.onMouseUp)

@mnogueron
Copy link
Owner

Edit: I think I have to change this, I did not see the event listeners that were added to the document

@mnogueron Could you please explain why you choose to add the event listeners for mousedown ad mouseup to the document instead of adding those via the props?

setMouseListeners = () => {
document.addEventListener('mousemove', this.onMouseMove)
document.addEventListener('mouseup', this.onMouseUp)
}
cleanMouseListeners = () => {
document.removeEventListener('mousemove', this.onMouseMove)
document.removeEventListener('mouseup', this.onMouseUp)

The reason to set the listener on the document and not on the actual component via props is that you still want to catch events when the mouse is leaving the component boundaries.

@mnogueron
Copy link
Owner

@n1ru4l I would rather see a use of deconstructing props, to pass down the rest of the props given to the PanZoom to the first div, and only combine the listeners that need to be combined.
It feels a bit hard to understand the way you did it, and makes the implementation rely on a static list of listener names. It would be easier if we were just passing down the props.

@n1ru4l
Copy link
Contributor Author

n1ru4l commented May 27, 2019

Sure let's do it like that!

@n1ru4l n1ru4l mentioned this pull request May 27, 2019
@n1ru4l
Copy link
Contributor Author

n1ru4l commented May 27, 2019

@mnogueron Done 😊

Copy link
Owner

@mnogueron mnogueron left a comment

Choose a reason for hiding this comment

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

@n1ru4l Sweat modifications!
Just same small comments but overwise it's good to go 🙂

src/PanZoom.js Outdated Show resolved Hide resolved
src/PanZoom.js Outdated Show resolved Hide resolved
src/PanZoom.js Outdated Show resolved Hide resolved
src/PanZoom.js Outdated Show resolved Hide resolved
src/PanZoom.js Outdated Show resolved Hide resolved
Copy link
Owner

@mnogueron mnogueron left a comment

Choose a reason for hiding this comment

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

@n1ru4l Perfect! Just need to fix the merge issue and it's good to go! :)

src/PanZoom.js Outdated Show resolved Hide resolved
@n1ru4l
Copy link
Contributor Author

n1ru4l commented Jun 4, 2019

@mnogueron Done!

@mnogueron mnogueron merged commit 7fb1aac into mnogueron:master Jun 4, 2019
@n1ru4l n1ru4l deleted the feat-event-handlers branch June 4, 2019 08:13
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