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

Event improvements #6218

Merged
merged 9 commits into from
Feb 23, 2018
Merged

Event improvements #6218

merged 9 commits into from
Feb 23, 2018

Conversation

jfirebaugh
Copy link
Contributor

Tested in Mac Chrome, Mac Firefox, iOS Safari.

Copy link
Contributor

@anandthakker anandthakker left a 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);
});
Copy link
Contributor

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.

Copy link

Choose a reason for hiding this comment

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

<3

originalEvent: e
}));
function fireTouchEvent(type: string, originalEvent: TouchEvent) {
map.fire(new MapTouchEvent(type, map, originalEvent));
Copy link
Contributor

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}
Copy link
Contributor

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}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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});
Copy link
Contributor

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

@jfirebaugh
Copy link
Contributor Author

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.?

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.

@lucaswoj
Copy link
Contributor

Looks great @jfirebaugh! Thank you for improving the clarity & robustness of our event type system while working on this new feature.

Copy link
Contributor

@mollymerp mollymerp left a 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants