Skip to content

Commit 548bd3e

Browse files
committed
Fix flow 0.33.0 errors, add lint to build
1 parent d0ac84c commit 548bd3e

File tree

10 files changed

+30
-16
lines changed

10 files changed

+30
-16
lines changed

.flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ lib/
66
index.js
77

88
[libs]
9+
interfaces/
910

1011
[options]
1112
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowFixMe.*

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ before_install:
1414
install:
1515
- node --version
1616
- yarn install
17+
- npm run lint
1718
cache:
1819
directories:
1920
- $HOME/.yarn-cache

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ clean:
1313
rm -rf dist
1414

1515
lint:
16-
# FIXME this is usually global
17-
flow check
16+
@$(BIN)/flow
1817
@$(BIN)/eslint lib/* lib/utils/* specs/*
1918

2019
build: $(LIB) $(MIN)

interfaces/dom.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Missing in Flow
2+
declare class SVGElement extends HTMLElement {
3+
}
4+
5+
// Missing targetTouches
6+
declare class TouchEvent2 extends TouchEvent {
7+
changedTouches: TouchList;
8+
targetTouches: TouchList;
9+
};
10+
11+
declare type MouseTouchEvent = MouseEvent & TouchEvent2;

lib/DraggableCore.es6

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export default class DraggableCore extends React.Component {
190190
if (this.props.enableUserSelectHack) removeUserSelectStyles(ownerDocument.body);
191191
}
192192

193-
handleDragStart: EventHandler<MouseEvent> = (e) => {
193+
handleDragStart: EventHandler<MouseTouchEvent> = (e) => {
194194
// Make it possible to attach event handlers on top of this one.
195195
this.props.onMouseDown(e);
196196

@@ -251,7 +251,7 @@ export default class DraggableCore extends React.Component {
251251
addEvent(ownerDocument, dragEventFor.stop, this.handleDragStop);
252252
};
253253

254-
handleDrag: EventHandler<MouseEvent> = (e) => {
254+
handleDrag: EventHandler<MouseTouchEvent> = (e) => {
255255

256256
// Get the current drag point from the event. This is used as the offset.
257257
const position = getControlPosition(e, this.state.touchIdentifier, this);
@@ -276,10 +276,11 @@ export default class DraggableCore extends React.Component {
276276
const shouldUpdate = this.props.onDrag(e, coreEvent);
277277
if (shouldUpdate === false) {
278278
try {
279+
// $FlowIgnore
279280
this.handleDragStop(new MouseEvent('mouseup'));
280281
} catch (err) {
281282
// Old browsers
282-
const event = ((document.createEvent('MouseEvents'): any): MouseEvent);
283+
const event = ((document.createEvent('MouseEvents'): any): MouseTouchEvent);
283284
// I see why this insanity was deprecated
284285
// $FlowIgnore
285286
event.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
@@ -294,7 +295,7 @@ export default class DraggableCore extends React.Component {
294295
});
295296
};
296297

297-
handleDragStop: EventHandler<MouseEvent> = (e) => {
298+
handleDragStop: EventHandler<MouseTouchEvent> = (e) => {
298299
if (!this.state.dragging) return;
299300

300301
const position = getControlPosition(e, this.state.touchIdentifier, this);
@@ -324,27 +325,27 @@ export default class DraggableCore extends React.Component {
324325
removeEvent(ownerDocument, dragEventFor.stop, this.handleDragStop);
325326
};
326327

327-
onMouseDown: EventHandler<MouseEvent> = (e) => {
328+
onMouseDown: EventHandler<MouseTouchEvent> = (e) => {
328329
dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
329330

330331
return this.handleDragStart(e);
331332
};
332333

333-
onMouseUp: EventHandler<MouseEvent> = (e) => {
334+
onMouseUp: EventHandler<MouseTouchEvent> = (e) => {
334335
dragEventFor = eventsFor.mouse;
335336

336337
return this.handleDragStop(e);
337338
};
338339

339340
// Same as onMouseDown (start drag), but now consider this a touch device.
340-
onTouchStart: EventHandler<MouseEvent> = (e) => {
341+
onTouchStart: EventHandler<MouseTouchEvent> = (e) => {
341342
// We're on a touch device now, so change the event handlers
342343
dragEventFor = eventsFor.touch;
343344

344345
return this.handleDragStart(e);
345346
};
346347

347-
onTouchEnd: EventHandler<MouseEvent> = (e) => {
348+
onTouchEnd: EventHandler<MouseTouchEvent> = (e) => {
348349
// We're on a touch device now, so change the event handlers
349350
dragEventFor = eventsFor.touch;
350351

lib/utils/domFns.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ export function createSVGTransform({x, y}: {x: number, y: number}): string {
114114
return 'translate(' + x + ',' + y + ')';
115115
}
116116

117-
export function getTouch(e: MouseEvent, identifier: number): ?{clientX: number, clientY: number} {
117+
export function getTouch(e: MouseTouchEvent, identifier: number): ?{clientX: number, clientY: number} {
118118
return (e.targetTouches && findInArray(e.targetTouches, t => identifier === t.identifier)) ||
119119
(e.changedTouches && findInArray(e.changedTouches, t => identifier === t.identifier));
120120
}
121121

122-
export function getTouchIdentifier(e: MouseEvent): ?number {
122+
export function getTouchIdentifier(e: MouseTouchEvent): ?number {
123123
if (e.targetTouches && e.targetTouches[0]) return e.targetTouches[0].identifier;
124124
if (e.changedTouches && e.changedTouches[0]) return e.changedTouches[0].identifier;
125125
}

lib/utils/positionFns.es6

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function canDragY(draggable: Draggable): boolean {
6565
}
6666

6767
// Get {x, y} positions from event.
68-
export function getControlPosition(e: MouseEvent, touchIdentifier: ?number, draggableCore: DraggableCore): ?ControlPosition {
68+
export function getControlPosition(e: MouseTouchEvent, touchIdentifier: ?number, draggableCore: DraggableCore): ?ControlPosition {
6969
const touchObj = typeof touchIdentifier === 'number' ? getTouch(e, touchIdentifier) : null;
7070
if (typeof touchIdentifier === 'number' && !touchObj) return null; // not the right touch
7171
const node = ReactDOM.findDOMNode(draggableCore);
@@ -76,8 +76,7 @@ export function getControlPosition(e: MouseEvent, touchIdentifier: ?number, drag
7676

7777
// Create an data object exposed by <DraggableCore>'s events
7878
export function createCoreData(draggable: DraggableCore, x: number, y: number): DraggableData {
79-
// State changes are often (but not always!) async. We want the latest value.
80-
const state = draggable._pendingState || draggable.state;
79+
const state = draggable.state;
8180
const isStart = !isNum(state.lastX);
8281

8382
if (isStart) {

lib/utils/shims.es6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
// @credits https://gist.github.com/rogozhnikoff/a43cfed27c41e4e68cdc
3-
export function findInArray(array: Array<any>, callback: Function): any {
3+
export function findInArray(array: Array<any> | TouchList, callback: Function): any {
44
for (let i = 0, length = array.length; i < length; i++) {
55
if (callback.apply(callback, [array[i], i, array])) return array[i];
66
}

lib/utils/types.es6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22

3+
// eslint-disable-next-line no-use-before-define
34
export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void | false;
45

56
export type DraggableData = {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"babel-preset-stage-1": "^6.5.0",
4040
"eslint": "^3.1.1",
4141
"eslint-plugin-react": "^5.2.2",
42+
"flow-bin": "^0.33.0",
4243
"jasmine-core": "^2.4.1",
4344
"json-loader": "^0.5.4",
4445
"karma": "^1.1.1",

0 commit comments

Comments
 (0)