fix: The same observable object cannot appear twice in the same tree#2812
fix: The same observable object cannot appear twice in the same tree#2812
Conversation
--bug=1054451 --user=王孝刚 【应用嵌套】高级编排中应用关联设置用户输入参数的应用,会报该应用不可用 https://www.tapd.cn/57709429/s/1681701
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| ) | ||
| const merge_api_input_field_list = new_api_input_field_list.map((item: any) => { | ||
| const find_field = old_api_input_field_list.find( | ||
| (old_item: any) => old_item.variable == item.variable |
There was a problem hiding this comment.
The provided code looks generally correct, but there are a few areas where optimizations can be made:
-
Dealing with Duplicates: The
cloneDeepfunction is used to ensure that the original array structures (api_input_field_listanduser_input_field_list) are not modified within theupdate_fieldmethod. This can prevent unintended side effects. -
Performance Considerations: If
old_api_input_field_list,old_user_input_field_list,new_api_input_field_list, ornew_user_input_field_listcould be very large arrays, manually cloning them might become inefficient due to memory usage. In such cases, consider using deep-copying libraries specifically designed for performance, though this seems unnecessary unless explicitly specified in your context.
Here's the suggested enhancement to improve readability slightly by organizing the clones neatly:
const oldApiInputFieldList = cloneDeep(props.nodeModel.properties.node_data.api_input_field_list);
const oldUserInputFieldList = cloneDeep(props.nodeModel.properties.node_data.user_input_field_list);
if (isWorkFlow(ok.data.type)) {
const nodeData = ok.data.work_flow.nodes[0].properties.node_data;
const newApiInputFieldList = cloneDeep(ok.data.work_flow.nodes[0].properties.api_input_field_list);
const newUserInputFieldList = cloneDeep(ok.data.work_flow.nodes[0].properties.user_input_field_list);
const mergeApiInputFieldList = newApiInputFieldList.map((item: any) => {
const findField = oldApiInputFieldList.find((oldItem: any) => oldItem.variable === item.variable);
return findField || item; // Merge logic here
});
}In summary, maintaining clean and efficient code while handling potentially large data sets depends on specific needs and constraints. For simplicity and clarity, manual deep-cloning ensures correctness without significant overhead in many scenarios.
fix: The same observable object cannot appear twice in the same tree --bug=1054451 --user=王孝刚 【应用嵌套】高级编排中应用关联设置用户输入参数的应用,会报该应用不可用 https://www.tapd.cn/57709429/s/1681701