Skip to content

Commit 9e57ee2

Browse files
committed
chore(types): prep for Flow 0.151.2
This version has a new `method-unbinding` rule, and it can't understand our autobind helper.
1 parent 05b3a57 commit 9e57ee2

File tree

4 files changed

+46
-41
lines changed

4 files changed

+46
-41
lines changed

lib/ReactGridLayout.jsx

+38-31
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as React from "react";
44
import isEqual from "lodash.isequal";
55
import classNames from "classnames";
66
import {
7-
autoBindHandlers,
87
bottom,
98
childrenEqual,
109
cloneLayoutItem,
@@ -138,18 +137,6 @@ export default class ReactGridLayout extends React.Component<Props, State> {
138137

139138
dragEnterCounter: number = 0;
140139

141-
constructor(props: Props, context: any): void {
142-
super(props, context);
143-
autoBindHandlers(this, [
144-
"onDragStart",
145-
"onDrag",
146-
"onDragStop",
147-
"onResizeStart",
148-
"onResize",
149-
"onResizeStop"
150-
]);
151-
}
152-
153140
componentDidMount() {
154141
this.setState({ mounted: true });
155142
// Possibly call back with layout on mount. This should be done after correcting the layout width
@@ -252,12 +239,12 @@ export default class ReactGridLayout extends React.Component<Props, State> {
252239
* @param {Event} e The mousedown event
253240
* @param {Element} node The current dragging DOM element
254241
*/
255-
onDragStart(
242+
onDragStart: (i: string, x: number, y: number, GridDragEvent) => void = (
256243
i: string,
257244
x: number,
258245
y: number,
259246
{ e, node }: GridDragEvent
260-
): void {
247+
) => {
261248
const { layout } = this.state;
262249
const l = getLayoutItem(layout, i);
263250
if (!l) return;
@@ -268,7 +255,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
268255
});
269256

270257
return this.props.onDragStart(layout, l, l, null, e, node);
271-
}
258+
};
272259

273260
/**
274261
* Each drag movement create a new dragelement and move the element to the dragged location
@@ -278,7 +265,12 @@ export default class ReactGridLayout extends React.Component<Props, State> {
278265
* @param {Event} e The mousedown event
279266
* @param {Element} node The current dragging DOM element
280267
*/
281-
onDrag(i: string, x: number, y: number, { e, node }: GridDragEvent): void {
268+
onDrag: (i: string, x: number, y: number, GridDragEvent) => void = (
269+
i,
270+
x,
271+
y,
272+
{ e, node }
273+
) => {
282274
const { oldDragItem } = this.state;
283275
let { layout } = this.state;
284276
const { cols, allowOverlap } = this.props;
@@ -317,7 +309,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
317309
: compact(layout, compactType(this.props), cols),
318310
activeDrag: placeholder
319311
});
320-
}
312+
};
321313

322314
/**
323315
* When dragging stops, figure out which position the element is closest to and update its x and y.
@@ -327,12 +319,12 @@ export default class ReactGridLayout extends React.Component<Props, State> {
327319
* @param {Event} e The mousedown event
328320
* @param {Element} node The current dragging DOM element
329321
*/
330-
onDragStop(
331-
i: string,
332-
x: number,
333-
y: number,
334-
{ e, node }: GridDragEvent
335-
): void {
322+
onDragStop: (i: string, x: number, y: number, GridDragEvent) => void = (
323+
i,
324+
x,
325+
y,
326+
{ e, node }
327+
) => {
336328
if (!this.state.activeDrag) return;
337329

338330
const { oldDragItem } = this.state;
@@ -370,7 +362,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
370362
});
371363

372364
this.onLayoutMaybeChanged(newLayout, oldLayout);
373-
}
365+
};
374366

375367
onLayoutMaybeChanged(newLayout: Layout, oldLayout: ?Layout) {
376368
if (!oldLayout) oldLayout = this.state.layout;
@@ -380,7 +372,12 @@ export default class ReactGridLayout extends React.Component<Props, State> {
380372
}
381373
}
382374

383-
onResizeStart(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
375+
onResizeStart: (i: string, w: number, h: number, GridResizeEvent) => void = (
376+
i,
377+
w,
378+
h,
379+
{ e, node }
380+
) => {
384381
const { layout } = this.state;
385382
const l = getLayoutItem(layout, i);
386383
if (!l) return;
@@ -391,9 +388,14 @@ export default class ReactGridLayout extends React.Component<Props, State> {
391388
});
392389

393390
this.props.onResizeStart(layout, l, l, null, e, node);
394-
}
391+
};
395392

396-
onResize(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
393+
onResize: (i: string, w: number, h: number, GridResizeEvent) => void = (
394+
i,
395+
w,
396+
h,
397+
{ e, node }
398+
) => {
397399
const { layout, oldResizeItem } = this.state;
398400
const { cols, preventCollision, allowOverlap } = this.props;
399401

@@ -453,9 +455,14 @@ export default class ReactGridLayout extends React.Component<Props, State> {
453455
: compact(newLayout, compactType(this.props), cols),
454456
activeDrag: placeholder
455457
});
456-
}
458+
};
457459

458-
onResizeStop(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
460+
onResizeStop: (i: string, w: number, h: number, GridResizeEvent) => void = (
461+
i,
462+
w,
463+
h,
464+
{ e, node }
465+
) => {
459466
const { layout, oldResizeItem } = this.state;
460467
const { cols, allowOverlap } = this.props;
461468
const l = getLayoutItem(layout, i);
@@ -475,7 +482,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
475482
});
476483

477484
this.onLayoutMaybeChanged(newLayout, oldLayout);
478-
}
485+
};
479486

480487
/**
481488
* Create a placeholder object.

lib/ResponsiveReactGridLayout.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from "./responsiveUtils";
2222
import ReactGridLayout from "./ReactGridLayout";
2323

24+
// $FlowFixMe[method-unbinding]
2425
const type = obj => Object.prototype.toString.call(obj);
2526

2627
/**

lib/utils.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export function compactItem(
328328
l.y++;
329329
}
330330
}
331-
331+
332332
// Ensure that there are no negative positions
333333
l.y = Math.max(l.y, 0);
334334
l.x = Math.max(l.x, 0);
@@ -472,7 +472,7 @@ export function moveElement(
472472

473473
// There was a collision; abort
474474
if (preventCollision && collisions.length) {
475-
if(!allowOverlap){
475+
if (!allowOverlap) {
476476
log(`Collision prevented on ${l.i}, reverting.`);
477477
l.x = oldX;
478478
l.y = oldY;
@@ -724,7 +724,9 @@ export function synchronizeLayoutWithChildren(
724724

725725
// Correct the layout.
726726
const correctedLayout = correctBounds(layout, { cols: cols });
727-
return allowOverlap ? correctedLayout : compact(correctedLayout, compactType, cols);
727+
return allowOverlap
728+
? correctedLayout
729+
: compact(correctedLayout, compactType, cols);
728730
}
729731

730732
/**
@@ -781,11 +783,6 @@ export function compactType(
781783
return verticalCompact === false ? null : compactType;
782784
}
783785

784-
// Flow can't really figure this out, so we just use Object
785-
export function autoBindHandlers(el: Object, fns: Array<string>): void {
786-
fns.forEach(key => (el[key] = el[key].bind(el)));
787-
}
788-
789786
function log(...args) {
790787
if (!DEBUG) return;
791788
// eslint-disable-next-line no-console

test/examples/3-messy.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export default class MessyLayout extends React.PureComponent<Props, State> {
5656
});
5757
}
5858

59-
onLayoutChange(layout: Layout) {
59+
onLayoutChange: (Layout) => void = (layout: Layout) => {
6060
this.props.onLayoutChange(layout);
61-
}
61+
};
6262

6363
render(): React.Node {
6464
// eslint-disable-next-line no-unused-vars

0 commit comments

Comments
 (0)