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

More flow #5088

Merged
merged 2 commits into from
Aug 4, 2017
Merged

More flow #5088

merged 2 commits into from
Aug 4, 2017

Conversation

jfirebaugh
Copy link
Contributor

Up to 89% coverage now!

@jfirebaugh jfirebaugh requested a review from anandthakker August 2, 2017 22:52
@@ -35,7 +34,7 @@ module.exports = function (polygonRings, precision, debug) {
// a priority queue of cells in order of their "potential" (max distance to polygon)
const cellQueue = new Queue(null, compareMax);

if (cellSize === 0) return [minX, minY];
if (cellSize === 0) return new Point(minX, minY);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flow found this bug.

window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) {
// Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131:
// Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when
// using Control + left click
eventButton = 0;
}
return (e.type === 'mousemove' ? e.buttons & buttons === 0 : !this.isActive() && eventButton !== button);
return (e.type === 'mousemove' ? e.buttons && buttons === 0 : !this.isActive() && eventButton !== button);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this because flow was complaining, but I'm not sure it's correct... the intent is pretty obscure.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, yeah. Peeking at the history, I actually suspect that this was intended to be (e.buttons & buttons) === 0, but I'm still not exactly sure what it's meant to be doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think (e.buttons & buttons) === 0 was indeed the intention, but in fact that prevents drag pan/rotate operations from working on Safari, which does not support the buttons property. Whereas e.buttons & buttons === 0 was simply always false, so mousemove events were never ignored, which is harmless!

To fix this, I'm going to remove the logic for ignoring mousemove events. Since it was never ignoring them, and we never noticed, it must be unnecessary.

@@ -197,7 +209,7 @@ class DragPanHandler {
if (e.ctrlKey) return true;
const buttons = 1, // left button
button = 0; // left button
return (e.type === 'mousemove' ? e.buttons & buttons === 0 : e.button && e.button !== button);
return (e.type === 'mousemove' ? e.buttons && buttons === 0 : e.button && e.button !== button);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto.

@@ -386,7 +386,7 @@ class Camera extends Evented {
return 0;
}), ["bottom", "left", "right", "top"])) {
util.warnOnce("options.padding must be a positive number, or an Object with keys 'bottom', 'left', 'right', 'top'");
return;
return this;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flow found this bug.

@@ -410,7 +410,7 @@ class Camera extends Evented {

if (scaleY < 0 || scaleX < 0) {
util.warnOnce('Map cannot fit within canvas with the given bounds, padding, and/or offset.');
return;
return this;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flow found this bug.

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.

🎉 💯

One suggestion -- alternative to (null: any) by typing a couple properties as maybes: 0229a56

@@ -967,7 +1076,7 @@ function getSizeVertexData(layer, tileZoom, stopZoomLevels, sizeProperty, featur
) {
// source function
return [
10 * layer.getLayoutValue(sizeProperty, {}, featureProperties)
10 * layer.getLayoutValue(sizeProperty, ({} : any), featureProperties)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be null instead of ({}: any), but we can get that later.

window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) {
// Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131:
// Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when
// using Control + left click
eventButton = 0;
}
return (e.type === 'mousemove' ? e.buttons & buttons === 0 : !this.isActive() && eventButton !== button);
return (e.type === 'mousemove' ? e.buttons && buttons === 0 : !this.isActive() && eventButton !== button);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, yeah. Peeking at the history, I actually suspect that this was intended to be (e.buttons & buttons) === 0, but I'm still not exactly sure what it's meant to be doing.

@@ -1156,7 +1184,7 @@ class Map extends Camera {
image: HTMLImageElement | $ArrayBufferView,
options?: {width: number, height: number, pixelRatio: number}
) {
this.style.spriteAtlas.addImage(name, image, options);
this.style.spriteAtlas.addImage(name, image, (options : any));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just type options as optional on SpriteAtlas.addImage as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm rewriting this code as part of #4876; will be addressed there.

@anandthakker
Copy link
Contributor

@jfirebaugh whoops the test failure is from a mistake in my suggested change. Fix here: 3567a61

@jfirebaugh
Copy link
Contributor Author

Going to go ahead and revert that; we should do a general pass over any casts as we finish up flow typing.

@jfirebaugh jfirebaugh merged commit 65afc08 into master Aug 4, 2017
@jfirebaugh jfirebaugh deleted the more-flow branch August 4, 2017 01:31
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