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

@ -18,15 +18,15 @@ import {
import { ExcalidrawElement } from "../element/types";
import { AppState } from "../types";
function getElementIndices(
const getElementIndices = (
direction: "left" | "right",
elements: readonly ExcalidrawElement[],
appState: AppState,
) {
) => {
const selectedIndices: number[] = [];
let deletedIndicesCache: number[] = [];
function cb(element: ExcalidrawElement, index: number) {
const cb = (element: ExcalidrawElement, index: number) => {
if (element.isDeleted) {
// we want to build an array of deleted elements that are preceeding
// a selected element so that we move them together
@ -39,7 +39,7 @@ function getElementIndices(
// of selected/deleted elements, of after encountering non-deleted elem
deletedIndicesCache = [];
}
}
};
// sending back → select contiguous deleted elements that are to the left of
// selected element(s)
@ -59,19 +59,19 @@ function getElementIndices(
}
// sort in case we were gathering indexes from right to left
return selectedIndices.sort();
}
};
function moveElements(
const moveElements = (
func: typeof moveOneLeft,
elements: readonly ExcalidrawElement[],
appState: AppState,
) {
) => {
const _elements = elements.slice();
const direction =
func === moveOneLeft || func === moveAllLeft ? "left" : "right";
const indices = getElementIndices(direction, _elements, appState);
return func(_elements, indices);
}
};
export const actionSendBackward = register({
name: "sendBackward",

View file

@ -2,7 +2,7 @@ import { Action } from "./types";
export let actions: readonly Action[] = [];
export function register(action: Action): Action {
export const register = (action: Action): Action => {
actions = actions.concat(action);
return action;
}
};