Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ provide('get_extra', get_extra)
const sourceChange = (node_id: string) => {
base_form_data.value.node_id = node_id
const n = source_node_list.value.find((n: any) => n.id == node_id)
extra.value.current_tool_id = n.properties.node_data.tool_lib_id
if (n.properties.node_data && n.properties.node_data.tool_lib_id) {
extra.value.current_tool_id = n.properties.node_data.tool_lib_id
}
node_id = n
? [WorkflowType.DataSourceLocalNode, WorkflowType.DataSourceWebNode].includes(n.type)
? n.type
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet seems mostly correct for its purpose, but there is one suggestion for improvement:

if (n !== undefined && n.properties.node_data && n.properties.node_data.tool_lib_id) {
  extra.value.current_tool_id = n.properties.node_data.tool_lib_id;
}

In JavaScript/TypeScript, undefined cannot be used directly to check for truthiness due to coercion rules. Using strict equality checks (!==) or ensuring that n is defined prevents unnecessary comparisons with other falsy values. This change improves clarity and correctness.

Here's the optimized version of the function:

const sourceChange = (node_id: string) => {
  base_form_data.value.node_id = node_id
  const n = source_node_list.value.find((n: any) => n.id === node_id);
  if (n && n.properties.node_data?.tool_lib_id) {
    extra.value.current_tool_id = n.properties.node_data.tool_lib_id;
  }
  // ... rest of the original function ...
};

This modification adds a conditional check before accessing n.type after filtering source_node_list. The use of optional chaining operator (?.) makes the expression safer by avoiding errors when n.properties.node_data is not available.

Expand Down
Loading