From efb1983ed1b19dd32a3086ba261c0664c17a4186 Mon Sep 17 00:00:00 2001 From: ZLY Date: Tue, 14 Oct 2025 15:18:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(flowEditor):=20=E6=B7=BB=E5=8A=A0=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=B0=E5=BD=95=E5=BF=AB=E7=85=A7=E9=98=B2=E6=8A=96?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 lodash 的 debounce 方法优化性能 - 对 takeSnapshot 事件处理函数进行防抖处理 - 设置防抖延迟时间为 100 毫秒 - 避免频繁触发快照导致的性能问题 --- src/pages/flowEditor/components/historyContext.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/flowEditor/components/historyContext.tsx b/src/pages/flowEditor/components/historyContext.tsx index 35bb9ca..00ba4b3 100644 --- a/src/pages/flowEditor/components/historyContext.tsx +++ b/src/pages/flowEditor/components/historyContext.tsx @@ -1,4 +1,5 @@ import React, { createContext, useContext, useState, useCallback, useRef, useEffect } from 'react'; +import { debounce } from 'lodash'; import { Node, Edge } from '@xyflow/react'; interface HistoryContextType { @@ -147,11 +148,11 @@ const HistoryProvider: React.FC = ({ // 监听 takeSnapshot 事件 useEffect(() => { - const handleTakeSnapshot = ((event: CustomEvent) => { + const handleTakeSnapshot = debounce((event: CustomEvent) => { const { nodes, edges } = event.detail; updateCurrentState(nodes, edges); takeSnapshot(); - }) as EventListener; + }, 100) as EventListener; document.addEventListener('takeSnapshot', handleTakeSnapshot); return () => {