Skip to content

Commit

Permalink
fix:修复nodes多个重复节点,导致节点信息没有更新到最新的节点的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
昔梦 committed Nov 29, 2024
1 parent 6a420f6 commit 5368587
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/x-flow/src/components/NodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import produce from 'immer';
import { debounce } from 'lodash';
import React, { FC, useContext, useEffect, useState } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { ConfigContext } from '../../models/context';
import { useStore } from '../../hooks/useStore';
import { ConfigContext } from '../../models/context';

interface INodeEditorProps {
data: any;
Expand Down Expand Up @@ -36,12 +36,18 @@ const NodeEditor: FC<INodeEditorProps> = (props: any) => {
setCustomVal(data);
} else {
}

}, [JSON.stringify(data), id]);

const handleNodeValueChange = debounce((data: any) => {
const newNodes = produce(nodes, draft => {
const node = draft.find(n => n.id === id);
let node = null;
// 反向查询ID,因为有多个ID相同的元素
for (let i = draft?.length - 1; i >= 0; i--) {
if (draft[i].id === id) {
node = draft[i];
break;
}
}
if (node) {
// 更新节点的 data
node.data = { ...node.data, ...data };
Expand Down
9 changes: 8 additions & 1 deletion packages/x-flow/src/components/PanelContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ const Panel: FC<IPanelProps> = (props: any) => {

const handleNodeValueChange = debounce((data: any) => {
const newNodes = produce(nodes, draft => {
const node = draft.find(n => n.id === id);
let node = null;
// 反向查询ID,因为有多个ID相同的元素
for (let i = draft?.length - 1; i >= 0; i--) {
if (draft[i].id === id) {
node = draft[i];
break;
}
}
if (node) {
// 更新节点的 data
node.data = { ...node.data, ...data };
Expand Down

0 comments on commit 5368587

Please sign in to comment.