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

@ -6,10 +6,10 @@ import { getElementAbsoluteCoords, getElementBounds } from "../element";
import { AppState } from "../types";
import { newElementWith } from "../element/mutateElement";
export function getElementsWithinSelection(
export const getElementsWithinSelection = (
elements: readonly NonDeletedExcalidrawElement[],
selection: NonDeletedExcalidrawElement,
) {
) => {
const [
selectionX1,
selectionY1,
@ -29,12 +29,12 @@ export function getElementsWithinSelection(
selectionY2 >= elementY2
);
});
}
};
export function deleteSelectedElements(
export const deleteSelectedElements = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) {
) => {
return {
elements: elements.map((el) => {
if (appState.selectedElementIds[el.id]) {
@ -47,24 +47,24 @@ export function deleteSelectedElements(
selectedElementIds: {},
},
};
}
};
export function isSomeElementSelected(
export const isSomeElementSelected = (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
): boolean {
): boolean => {
return elements.some((element) => appState.selectedElementIds[element.id]);
}
};
/**
* Returns common attribute (picked by `getAttribute` callback) of selected
* elements. If elements don't share the same value, returns `null`.
*/
export function getCommonAttributeOfSelectedElements<T>(
export const getCommonAttributeOfSelectedElements = <T>(
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
getAttribute: (element: ExcalidrawElement) => T,
): T | null {
): T | null => {
const attributes = Array.from(
new Set(
getSelectedElements(elements, appState).map((element) =>
@ -73,20 +73,20 @@ export function getCommonAttributeOfSelectedElements<T>(
),
);
return attributes.length === 1 ? attributes[0] : null;
}
};
export function getSelectedElements(
export const getSelectedElements = (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
) {
) => {
return elements.filter((element) => appState.selectedElementIds[element.id]);
}
};
export function getTargetElement(
export const getTargetElement = (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
) {
) => {
return appState.editingElement
? [appState.editingElement]
: getSelectedElements(elements, appState);
}
};