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
33 changed files with 155 additions and 125 deletions

View File

@ -7,8 +7,9 @@ import {
import { DEFAULT_VERSION } from "../constants";
import { t } from "../i18n";
import { copyTextToSystemClipboard } from "../clipboard";
import { AppState } from "../types";
import { NonDeletedExcalidrawElement } from "../element/types";
import { UIAppState } from "../types";
type StorageSizes = { scene: number; total: number };
const STORAGE_SIZE_TIMEOUT = 500;
@ -23,7 +24,7 @@ const getStorageSizes = debounce((cb: (sizes: StorageSizes) => void) => {
type Props = {
setToast: (message: string) => void;
elements: readonly NonDeletedExcalidrawElement[];
appState: AppState;
appState: UIAppState;
};
const CustomStats = (props: Props) => {
const [storageSizes, setStorageSizes] = useState<StorageSizes>({

View File

@ -18,7 +18,7 @@ import { getFrame } from "../../utils";
const exportToExcalidrawPlus = async (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
appState: Partial<AppState>,
files: BinaryFiles,
) => {
const firebase = await loadFirebaseStorage();
@ -75,7 +75,7 @@ const exportToExcalidrawPlus = async (
export const ExportToExcalidrawPlus: React.FC<{
elements: readonly NonDeletedExcalidrawElement[];
appState: AppState;
appState: Partial<AppState>;
files: BinaryFiles;
onError: (error: Error) => void;
}> = ({ elements, appState, files, onError }) => {

View File

@ -284,7 +284,7 @@ export const loadScene = async (
export const exportToBackend = async (
elements: readonly ExcalidrawElement[],
appState: AppState,
appState: Partial<AppState>,
files: BinaryFiles,
) => {
const encryptionKey = await generateEncryptionKey("string");

View File

@ -32,6 +32,7 @@ import {
ExcalidrawImperativeAPI,
BinaryFiles,
ExcalidrawInitialDataState,
UIAppState,
} from "../types";
import {
debounce,
@ -550,7 +551,7 @@ const ExcalidrawWrapper = () => {
const onExportToBackend = async (
exportedElements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
appState: Partial<AppState>,
files: BinaryFiles,
canvas: HTMLCanvasElement | null,
) => {
@ -581,7 +582,7 @@ const ExcalidrawWrapper = () => {
const renderCustomStats = (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
appState: UIAppState,
) => {
return (
<CustomStats