Skip to content

Commit 8b95960

Browse files
committed
refactor: handle deep replace
1 parent 555338b commit 8b95960

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/core/reducer/reduce.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,18 @@ export const replaceAction = <UserData extends Data>(
115115
return walkTree<UserData>(
116116
state,
117117
(content) => content,
118-
(childItem) => {
118+
(childItem, path) => {
119+
const pathIds = path.map((p) => p.split(":")[0]);
120+
119121
if (childItem.props.id === action.data.props.id) {
120122
return action.data;
121123
} else if (childItem.props.id === parentId) {
122124
return childItem;
123125
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
124-
// This node is in the path of the target node
126+
// Node is parent of target
127+
return childItem;
128+
} else if (pathIds.indexOf(action.data.props.id) > -1) {
129+
// Node is child target
125130
return childItem;
126131
}
127132

0 commit comments

Comments
 (0)