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

@ -30,7 +30,7 @@ import colors from "../colors";
type HandlerRectanglesRet = keyof ReturnType<typeof handlerRectangles>;
function colorsForClientId(clientId: string) {
const colorsForClientId = (clientId: string) => {
// Naive way of getting an integer out of the clientId
const sum = clientId.split("").reduce((a, str) => a + str.charCodeAt(0), 0);
@ -41,9 +41,9 @@ function colorsForClientId(clientId: string) {
background: backgrounds[sum % backgrounds.length],
stroke: strokes[sum % strokes.length],
};
}
};
function strokeRectWithRotation(
const strokeRectWithRotation = (
context: CanvasRenderingContext2D,
x: number,
y: number,
@ -53,7 +53,7 @@ function strokeRectWithRotation(
cy: number,
angle: number,
fill?: boolean,
) {
) => {
context.translate(cx, cy);
context.rotate(angle);
if (fill) {
@ -62,22 +62,22 @@ function strokeRectWithRotation(
context.strokeRect(x - cx, y - cy, width, height);
context.rotate(-angle);
context.translate(-cx, -cy);
}
};
function strokeCircle(
const strokeCircle = (
context: CanvasRenderingContext2D,
x: number,
y: number,
width: number,
height: number,
) {
) => {
context.beginPath();
context.arc(x + width / 2, y + height / 2, width / 2, 0, Math.PI * 2);
context.fill();
context.stroke();
}
};
export function renderScene(
export const renderScene = (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
selectionElement: NonDeletedExcalidrawElement | null,
@ -98,7 +98,7 @@ export function renderScene(
renderSelection?: boolean;
renderOptimizations?: boolean;
} = {},
) {
) => {
if (!canvas) {
return { atLeastOneVisibleElement: false };
}
@ -461,9 +461,9 @@ export function renderScene(
context.scale(1 / scale, 1 / scale);
return { atLeastOneVisibleElement: visibleElements.length > 0, scrollBars };
}
};
function isVisibleElement(
const isVisibleElement = (
element: ExcalidrawElement,
viewportWidth: number,
viewportHeight: number,
@ -476,7 +476,7 @@ function isVisibleElement(
scrollY: FlooredNumber;
zoom: number;
},
) {
) => {
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
// Apply zoom
@ -492,10 +492,10 @@ function isVisibleElement(
y2 + scrollY - viewportHeightDiff / 2 >= 0 &&
y1 + scrollY - viewportHeightDiff / 2 <= viewportHeightWithZoom
);
}
};
// This should be only called for exporting purposes
export function renderSceneToSvg(
export const renderSceneToSvg = (
elements: readonly NonDeletedExcalidrawElement[],
rsvg: RoughSVG,
svgRoot: SVGElement,
@ -506,7 +506,7 @@ export function renderSceneToSvg(
offsetX?: number;
offsetY?: number;
} = {},
) {
) => {
if (!svgRoot) {
return;
}
@ -522,4 +522,4 @@ export function renderSceneToSvg(
);
}
});
}
};