* Helper function to create a variable on the given workspace. * * @param workspace The workspace in which to create the variable. It may be a * flyout workspace or main workspace. * @param id The ID to use to create the variable, or null. * @param opt_name The string to use to create the
( workspace: Workspace, id: string | null, opt_name?: string, opt_type?: string, )
| 730 | * combination. |
| 731 | */ |
| 732 | function createVariable( |
| 733 | workspace: Workspace, |
| 734 | id: string | null, |
| 735 | opt_name?: string, |
| 736 | opt_type?: string, |
| 737 | ): IVariableModel<IVariableState> { |
| 738 | const variableMap = workspace.getVariableMap(); |
| 739 | const potentialVariableMap = workspace.getPotentialVariableMap(); |
| 740 | // Variables without names get uniquely named for this workspace. |
| 741 | if (!opt_name) { |
| 742 | const ws = workspace.isFlyout |
| 743 | ? (workspace as WorkspaceSvg).targetWorkspace |
| 744 | : workspace; |
| 745 | opt_name = generateUniqueName(ws!); |
| 746 | } |
| 747 | |
| 748 | // Create a potential variable if in the flyout. |
| 749 | let variable = null; |
| 750 | if (potentialVariableMap) { |
| 751 | variable = potentialVariableMap.createVariable( |
| 752 | opt_name, |
| 753 | opt_type, |
| 754 | id ?? undefined, |
| 755 | ); |
| 756 | } else { |
| 757 | // In the main workspace, create a real variable. |
| 758 | variable = variableMap.createVariable(opt_name, opt_type, id); |
| 759 | } |
| 760 | return variable; |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Helper function to get the list of variables that have been added to the |
no test coverage detected