-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Event improvements #6218
Event improvements #6218
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 this is an excellent refactor.
@jfirebaugh what's your thinking re: *move
events: does it still make sense for handlers to manage listening to them directly, or should we have the bindHandlers
listeners dispatch to the appropriate handlers for these like we're doing for *{start,end}
, etc.? (I can see why we might not want to have *move
support default prevention, but I'm wondering whether it might still be worthwhile to have all events go through a unified set of listeners.)
|
||
map.on('mousemove', onMove); | ||
map.once('mouseup', onUp); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 this is such a nice simplification, and (therefore, IMO) confirms this API design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
src/ui/bind_handlers.js
Outdated
originalEvent: e | ||
})); | ||
function fireTouchEvent(type: string, originalEvent: TouchEvent) { | ||
map.fire(new MapTouchEvent(type, map, originalEvent)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just inline these
* | ||
* * On `mousedown` events, the behavior of {@link DragPanHandler} | ||
* * On `mousedown` events, the behavior of {@link DragRotateHandler} | ||
* * On `mousedown` events, the behavior of {@link BoxZoomHandler} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also have:
- On
wheel
events, the behavior of{@link ScrollZoomHandler}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/ui/handler/drag_pan.js
Outdated
if (this._map.boxZoom.isActive()) return; | ||
if (this._map.dragRotate.isActive()) return; | ||
if (this.isActive()) return; | ||
|
||
if (e.touches) { | ||
if ((e.touches: any).length > 1) return; | ||
window.document.addEventListener('touchmove', this._onMove); | ||
window.document.addEventListener('touchmove', this._onMove, {capture: true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include comment mentioning why capture: true
The latter was what I tried initially, but I ended up reverting. The issue is that the drag handlers need to capture move events by binding the listener to the window (for the duration of the drag), while the general move event handler should receive only canvas container move events (but is permanent). So it's easier to keep them separated. |
Looks great @jfirebaugh! Thank you for improving the clarity & robustness of our event type system while working on this new feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks great! thanks for all the new tests, too!! 🥇
Changes the arguments of Evented#fire from (string, Object) to (Event) and updates all call sites. This paves the way for events to provide preventDefault(). It also allows Error subclasses to enforce conventions via types. Here, we enforce that the `error` property of error events is an Error, and correct several instances where it was a string instead.
3e240a9
to
e2ba66c
Compare
Tested in Mac Chrome, Mac Firefox, iOS Safari.