perf: use UIAppState where possible to reduce UI rerenders (#6560)

This commit is contained in:
David Luzar 2023-05-08 10:14:02 +02:00 committed by GitHub
parent 026949204d
commit 560231d365
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 155 additions and 125 deletions

View file

@ -1,3 +1,4 @@
import React from "react";
import {
PointerType,
ExcalidrawLinearElement,
@ -32,7 +33,6 @@ import type { FileSystemHandle } from "./data/filesystem";
import type { IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
import { ContextMenuItems } from "./components/ContextMenu";
import { Merge, ForwardRef, ValueOf } from "./utility-types";
import React from "react";
export type Point = Readonly<RoughPoint>;
@ -218,6 +218,15 @@ export type AppState = {
selectedLinearElement: LinearElementEditor | null;
};
export type UIAppState = Omit<
AppState,
| "suggestedBindings"
| "startBoundElement"
| "cursorButton"
| "scrollX"
| "scrollY"
>;
export type NormalizedZoomValue = number & { _brand: "normalizedZoom" };
export type Zoom = Readonly<{
@ -314,7 +323,7 @@ export interface ExcalidrawProps {
) => Promise<boolean> | boolean;
renderTopRightUI?: (
isMobile: boolean,
appState: AppState,
appState: UIAppState,
) => JSX.Element | null;
langCode?: Language["code"];
viewModeEnabled?: boolean;
@ -325,7 +334,7 @@ export interface ExcalidrawProps {
name?: string;
renderCustomStats?: (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
appState: UIAppState,
) => JSX.Element;
UIOptions?: Partial<UIOptions>;
detectScroll?: boolean;
@ -364,13 +373,13 @@ export type ExportOpts = {
saveFileToDisk?: boolean;
onExportToBackend?: (
exportedElements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
appState: UIAppState,
files: BinaryFiles,
canvas: HTMLCanvasElement | null,
) => void;
renderCustomUI?: (
exportedElements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
appState: UIAppState,
files: BinaryFiles,
canvas: HTMLCanvasElement | null,
) => JSX.Element;