refactor: Use arrow function where possible (#3315)

This commit is contained in:
Lipis 2021-03-29 17:09:20 +03:00 committed by GitHub
parent bb568a9670
commit 722e5ca845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 24 additions and 26 deletions

View File

@ -8,7 +8,7 @@ import { getCommonBounds, getNonDeletedElements } from "../element";
import { newElementWith } from "../element/mutateElement"; import { newElementWith } from "../element/mutateElement";
import { ExcalidrawElement } from "../element/types"; import { ExcalidrawElement } from "../element/types";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { CODES, KEYS } from "../keys"; import { CODES, KEYS } from "../keys";
import { getNormalizedZoom, getSelectedElements } from "../scene"; import { getNormalizedZoom, getSelectedElements } from "../scene";
import { centerScrollOn } from "../scene/scroll"; import { centerScrollOn } from "../scene/scroll";

View File

@ -8,7 +8,7 @@ import { Tooltip } from "../components/Tooltip";
import { DarkModeToggle, Appearence } from "../components/DarkModeToggle"; import { DarkModeToggle, Appearence } from "../components/DarkModeToggle";
import { loadFromJSON, saveAsJSON } from "../data"; import { loadFromJSON, saveAsJSON } from "../data";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { register } from "./register"; import { register } from "./register";
import { supported } from "browser-fs-access"; import { supported } from "browser-fs-access";

View File

@ -3,7 +3,7 @@ import { ActionManager } from "../actions/manager";
import { getNonDeletedElements } from "../element"; import { getNonDeletedElements } from "../element";
import { ExcalidrawElement } from "../element/types"; import { ExcalidrawElement } from "../element/types";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { import {
canChangeSharpness, canChangeSharpness,
canHaveArrowheads, canHaveArrowheads,

View File

@ -1,4 +1,3 @@
import React from "react";
import clsx from "clsx"; import clsx from "clsx";
export const ButtonIconCycle = <T extends any>({ export const ButtonIconCycle = <T extends any>({
@ -14,11 +13,11 @@ export const ButtonIconCycle = <T extends any>({
}) => { }) => {
const current = options.find((op) => op.value === value); const current = options.find((op) => op.value === value);
function cycle() { const cycle = () => {
const index = options.indexOf(current!); const index = options.indexOf(current!);
const next = (index + 1) % options.length; const next = (index + 1) % options.length;
onChange(options[next].value); onChange(options[next].value);
} };
return ( return (
<label key={group} className={clsx({ active: current!.value !== null })}> <label key={group} className={clsx({ active: current!.value !== null })}>

View File

@ -2,7 +2,7 @@ import React from "react";
import clsx from "clsx"; import clsx from "clsx";
import { ToolButton } from "./ToolButton"; import { ToolButton } from "./ToolButton";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { users } from "./icons"; import { users } from "./icons";
import "./CollabButton.scss"; import "./CollabButton.scss";

View File

@ -2,7 +2,7 @@ import clsx from "clsx";
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { useCallbackRefState } from "../hooks/useCallbackRefState"; import { useCallbackRefState } from "../hooks/useCallbackRefState";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import "./Dialog.scss"; import "./Dialog.scss";
import { back, close } from "./icons"; import { back, close } from "./icons";

View File

@ -6,7 +6,7 @@ import { canvasToBlob } from "../data/blob";
import { NonDeletedExcalidrawElement } from "../element/types"; import { NonDeletedExcalidrawElement } from "../element/types";
import { CanvasError } from "../errors"; import { CanvasError } from "../errors";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { getSelectedElements, isSomeElementSelected } from "../scene"; import { getSelectedElements, isSomeElementSelected } from "../scene";
import { exportToCanvas, getExportSize } from "../scene/export"; import { exportToCanvas, getExportSize } from "../scene/export";
import { AppState } from "../types"; import { AppState } from "../types";

View File

@ -14,7 +14,7 @@ import { Library } from "../data/library";
import { isTextElement, showSelectedShapeActions } from "../element"; import { isTextElement, showSelectedShapeActions } from "../element";
import { NonDeletedExcalidrawElement } from "../element/types"; import { NonDeletedExcalidrawElement } from "../element/types";
import { Language, t } from "../i18n"; import { Language, t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { calculateScrollCenter, getSelectedElements } from "../scene"; import { calculateScrollCenter, getSelectedElements } from "../scene";
import { ExportType } from "../scene/types"; import { ExportType } from "../scene/types";
import { AppState, ExcalidrawProps, LibraryItem, LibraryItems } from "../types"; import { AppState, ExcalidrawProps, LibraryItem, LibraryItems } from "../types";

View File

@ -4,7 +4,7 @@ import React, { useEffect, useRef, useState } from "react";
import { close } from "../components/icons"; import { close } from "../components/icons";
import { MIME_TYPES } from "../constants"; import { MIME_TYPES } from "../constants";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { exportToSvg } from "../scene/export"; import { exportToSvg } from "../scene/export";
import { LibraryItem } from "../types"; import { LibraryItem } from "../types";
import "./LibraryUnit.scss"; import "./LibraryUnit.scss";

View File

@ -8,7 +8,7 @@ import {
getTotalStorageSize, getTotalStorageSize,
} from "../excalidraw-app/data/localStorage"; } from "../excalidraw-app/data/localStorage";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import { useIsMobile } from "../is-mobile";
import { getTargetElements } from "../scene"; import { getTargetElements } from "../scene";
import { AppState } from "../types"; import { AppState } from "../types";
import { debounce, getVersion, nFormatter } from "../utils"; import { debounce, getVersion, nFormatter } from "../utils";

View File

@ -161,7 +161,7 @@ const initializeScene = async (opts: {
return null; return null;
}; };
function ExcalidrawWrapper() { const ExcalidrawWrapper = () => {
// dimensions // dimensions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -347,9 +347,9 @@ function ExcalidrawWrapper() {
)} )}
</> </>
); );
} };
export default function ExcalidrawApp() { const ExcalidrawApp = () => {
return ( return (
<TopErrorBoundary> <TopErrorBoundary>
<CollabContextConsumer> <CollabContextConsumer>
@ -357,4 +357,6 @@ export default function ExcalidrawApp() {
</CollabContextConsumer> </CollabContextConsumer>
</TopErrorBoundary> </TopErrorBoundary>
); );
} };
export default ExcalidrawApp;

View File

@ -34,7 +34,4 @@ export const IsMobileProvider = ({
}; };
export const isMobile = () => getIsMobileMatcher().matches; export const isMobile = () => getIsMobileMatcher().matches;
export const useIsMobile = () => useContext(context);
export default function useIsMobile() {
return useContext(context);
}

View File

@ -349,12 +349,12 @@ const generateElementShape = (
if (element.type === "arrow") { if (element.type === "arrow") {
const { startArrowhead = null, endArrowhead = "arrow" } = element; const { startArrowhead = null, endArrowhead = "arrow" } = element;
function getArrowheadShapes( const getArrowheadShapes = (
element: ExcalidrawLinearElement, element: ExcalidrawLinearElement,
shape: Drawable[], shape: Drawable[],
position: "start" | "end", position: "start" | "end",
arrowhead: Arrowhead, arrowhead: Arrowhead,
) { ) => {
const arrowheadPoints = getArrowheadPoints( const arrowheadPoints = getArrowheadPoints(
element, element,
shape, shape,
@ -392,7 +392,7 @@ const generateElementShape = (
generator.line(x3, y3, x2, y2, options), generator.line(x3, y3, x2, y2, options),
generator.line(x4, y4, x2, y2, options), generator.line(x4, y4, x2, y2, options),
]; ];
} };
if (startArrowhead !== null) { if (startArrowhead !== null) {
const shapes = getArrowheadShapes( const shapes = getArrowheadShapes(

View File

@ -122,12 +122,12 @@ describe("resize rectangle ellipses and diamond elements", () => {
); );
}); });
function resize( const resize = (
element: ExcalidrawElement, element: ExcalidrawElement,
handleDir: TransformHandleDirection, handleDir: TransformHandleDirection,
mouseMove: [number, number], mouseMove: [number, number],
keyboardModifiers: KeyboardModifiers = {}, keyboardModifiers: KeyboardModifiers = {},
) { ) => {
mouse.select(element); mouse.select(element);
const handle = getTransformHandles(element, h.state.zoom, "mouse")[ const handle = getTransformHandles(element, h.state.zoom, "mouse")[
handleDir handleDir
@ -140,4 +140,4 @@ function resize(
mouse.move(mouseMove[0], mouseMove[1]); mouse.move(mouseMove[0], mouseMove[1]);
mouse.up(); mouse.up();
}); });
} };