Prefer arrow functions and callbacks (#1210)

This commit is contained in:
Lipis 2020-05-20 16:21:37 +03:00 committed by GitHub
parent 33fe223b5d
commit c427aa3cce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 784 additions and 847 deletions

View file

@ -3,21 +3,23 @@ import { mutateElement } from "./mutateElement";
import { isLinearElement } from "./typeChecks";
import { SHIFT_LOCKING_ANGLE } from "../constants";
export function isInvisiblySmallElement(element: ExcalidrawElement): boolean {
export const isInvisiblySmallElement = (
element: ExcalidrawElement,
): boolean => {
if (isLinearElement(element)) {
return element.points.length < 2;
}
return element.width === 0 && element.height === 0;
}
};
/**
* Makes a perfect shape or diagonal/horizontal/vertical line
*/
export function getPerfectElementSize(
export const getPerfectElementSize = (
elementType: string,
width: number,
height: number,
): { width: number; height: number } {
): { width: number; height: number } => {
const absWidth = Math.abs(width);
const absHeight = Math.abs(height);
@ -42,13 +44,13 @@ export function getPerfectElementSize(
height = absWidth * Math.sign(height);
}
return { width, height };
}
};
export function resizePerfectLineForNWHandler(
export const resizePerfectLineForNWHandler = (
element: ExcalidrawElement,
x: number,
y: number,
) {
) => {
const anchorX = element.x + element.width;
const anchorY = element.y + element.height;
const distanceToAnchorX = x - anchorX;
@ -77,14 +79,14 @@ export function resizePerfectLineForNWHandler(
height: nextHeight,
});
}
}
};
/**
* @returns {boolean} whether element was normalized
*/
export function normalizeDimensions(
export const normalizeDimensions = (
element: ExcalidrawElement | null,
): element is ExcalidrawElement {
): element is ExcalidrawElement => {
if (!element || (element.width >= 0 && element.height >= 0)) {
return false;
}
@ -106,4 +108,4 @@ export function normalizeDimensions(
}
return true;
}
};