Convert utils/snap to TS

Reviewed By: danielbuechele

Differential Revision: D16710422

fbshipit-source-id: 2f907904a7df24f6972952d0c7a63d7e6506e2ff
This commit is contained in:
John Knox
2019-08-12 03:02:16 -07:00
committed by Facebook Github Bot
parent a522afd64f
commit 9b6f3684cb
2 changed files with 5 additions and 6 deletions

View File

@@ -12,7 +12,7 @@ import {
maybeSnapLeft, maybeSnapLeft,
maybeSnapTop, maybeSnapTop,
SNAP_SIZE, SNAP_SIZE,
} from '../../utils/snap.js'; } from '../../utils/snap.tsx';
import styled from '../styled/index.js'; import styled from '../styled/index.js';
import invariant from 'invariant'; import invariant from 'invariant';
import React from 'react'; import React from 'react';

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import type {Rect} from './geometry.js'; import {Rect} from './geometry.js';
export const SNAP_SIZE = 16; export const SNAP_SIZE = 16;
@@ -19,10 +19,10 @@ export function getPossibleSnappedPosition(
getGap, getGap,
getNew, getNew,
}: { }: {
getNew: (win: Rect) => number, getNew: (win: Rect) => number;
getGap: (win: Rect) => number, getGap: (win: Rect) => number;
}, },
): ?number { ): number | undefined {
for (const win of windows) { for (const win of windows) {
const gap = Math.abs(getGap(win)); const gap = Math.abs(getGap(win));
if (gap >= 0 && gap < SNAP_SIZE) { if (gap >= 0 && gap < SNAP_SIZE) {
@@ -87,7 +87,6 @@ export function maybeSnapLeft(
// │A│B│ // │A│B│
// └─┴─┘ // └─┴─┘
const snapRight = getPossibleSnappedPosition(windows, { const snapRight = getPossibleSnappedPosition(windows, {
debug: true,
getGap: win => win.left - (props.width + left), getGap: win => win.left - (props.width + left),
getNew: win => win.left - props.width, getNew: win => win.left - props.width,
}); });