Menu Path:
|
Toolbar: >Shared JavaScript Libraries |
Read Access Rights:
|
Write Access Rights:
|
The Shared JavaScript Libraries manager allows you to add, edit or delete shared Javascript libraries and functions:
It is composed of a header bar and two panels: a Library Manager, and a Code Editor. Shared functions can be grouped into libraries although each function is self-contained.
If you do not have the prerequisite access rights, the Shared JavaScript Libraries manager is only available in read-only mode.
Viewing Libraries
To open the Shared JavaScript Libraries manager, perform one of the following actions:
- Navigate to View>Shared JavaScript Libraries.
- Select the button on the Rhapsody IDE menu bar and select Shared JavaScript Libraries.
- Press Ctrl+Shift+S.
The Shared JavaScript Libraries manager provides you with the following panels:
Panel | Description |
---|---|
Library Manager |
Displays a tree view of all libraries and functions on the engine, and enables you to manage libraries and functions |
Code Editor | Enables you to view and edit a function. |
Managing Libraries
The Shared JavaScript Libraries manager enables you to perform the following actions through the header bar:
Actions | Description |
---|---|
Add Function |
Add a new function to a library. To call a function, refer to Calling Shared Functions. The maximum size a JavaScript function can be is 16384 bytes. |
Add Library | Add a new library. |
Remove | Delete a function or a library with all corresponding functions. |
Check Out | Check out all functions in a library (not only the selected function). |
Check In | Check in the selected functions. |
Undo Check Out | Revert all changes made to the library and all functions in it. |
Show Uses | Display all components using a particular function or library. |
Filter | Perform text-based filtering to filter the list of displayed libraries. |
You can perform the following actions through the right-click menu in the Library Manager panel (actions available through the header bar are not listed):
Actions | Description |
---|---|
Rename a function. | |
Remove Function | Remove a function. |
Rename Library | Rename a library |
Remove Library | Remove a library |
Copy | Copy a library or function into memory. |
Paste | Paste a library or function into the Library Manager panel. |
Validate Function | Manually verify whether a shared function is syntactically correct. |
You can also open the right-click menu by pressing F2.
When editing a Javascript Library or function, the library cannot be edited unless the user editing the library has the 'Edit locker' access right for all lockers where the library is used. The Show Uses context menu item displays a list of the components that use the library.
Adding a Library
To create and add a new library:
- Open the Shared JavaScript Libraries manager.
- Either:
- Select Add Library in the right-click menu, or
- Select the Add Library button.
- Enter a name for the new library, or use the default name provided.
There is a potential performance impact in having large libraries. Therefore, it is recommended you only group related functions in multiple, smaller libraries, rather than putting all your functions in single, larger libraries.
Renaming a Library
To rename a library:
- Open the Shared JavaScript Libraries manager.
- Select a library in the Library Manager.
- Select Rename Library in the right-click menu.
- Enter a new name for the library.
- If the library or any function within the library is being used in any components, the Library Uses dialog is displayed. Select the OK to confirm renaming.
Renaming a library or a function that is used by Rhapsody components could prevent those components from working correctly. Each component that is calling a library or a function within the library must be manually reconfigured.
Deleting a Library
To delete a library:
- Open the Shared JavaScript Libraries manager.
- Select a library in the Library Manager.
- Either:
- Select Remove Library in the right-click menu, or
- Select the Remove button.
Select the Yes button in the dialog to proceed, or the No button to abort.
- If the library or any function within the library is being used in any components, the Library Uses dialog is displayed. Select the OK to confirm deletion.
Showing Library Use
The Show Uses tab in the Information panel of Rhapsody IDE enables you to determine which components are affected when you modify a particular library:
The Show Uses tab provides you with the following information:
Column | Description |
---|---|
Path | The path the component is located in. |
Function Name |
The name of the functions within the selected library. If the library is referenced without calling a function, the function name is blank. |
Component | The name of the component that it is referenced in. |
To determine which components are using a particular library:
- Open the Shared JavaScript Libraries manager.
- Select a library in the Library Manager panel.
- Select the Show Uses button (or Show Uses in the right-click menu) to display the library's uses in the Show Uses tab in the Information panel of Rhapsody IDE.
- To view or edit the configuration properties of a component using the shared JavaScript library:
- Double-click on the component path.
- Or alternatively, from the right-click menu, select Open Properties.
- Select the Close button to close the dialog.
Managing Functions
Adding a Function
- A function can invoke a function located in the same library, but cannot invoke a function located in a different library.
- It is recommended to make the function always return a value
- Function name must match its name in the tree view.
- It is not recommended to have nested functions with the same name as a Shared Function.
To create and add a new function:
- Open the Shared JavaScript Libraries manager.
- Either:
- Select Add Function in the right-click menu, or
- Select the Add Function button.
- Enter a name for the new function in the Library Manager panel, or use default one provided. The function can only be created in a library.
- Enter the JavaScript code.
Renaming a Function
To rename function:
- Open the Shared JavaScript Libraries manager.
- Select a library in the Library Manager panel.
- Select Rename Function in the right-click menu.
- Enter a new name for the function in the Tree View, function name in the code editor will automatically be renamed.
- If the function is being used in any component, Function Uses dialog is displayed. Select the OK button to confirm renaming.
Renaming a function in the tree view automatically renames a function name in the Code Editor. However, renaming a function in the Code Editor does not rename a function name in a tree view. Also note, as auto-renaming in the Code Editor is a best-effort approach, you should always check if the result is desired.
Editing a Function
Editing a single shared function checks out whole JavaScript library where the shared function is including other shared functions in it.
To edit a function:
- Open the Shared JavaScript Libraries manager.
- Open the function you want to edit and start editing it in the Code Editor.
Modifying a function that is already used by Rhapsody components could prevent those components from working correctly. It is recommended to always check affected components using 'Show Uses' and make sure the result is desired.
Deleting a Function
To delete a function:
- Open the Shared JavaScript Libraries manager.
- Select a function in the Library Manager panel.
- Either:
- Select Remove Function in the right-click menu, or
- Select the Remove button.
- Select the Yes button in the dialog to proceed, or the No button to abort.
- If the function is being used in any component, Function Uses dialog is displayed. Select the OK button to confirm deletion.
Showing Function Use
The Show Uses tab in the Information panel of Rhapsody IDE enables you to determine which components are affected when you modify a particular function:
The Show Uses tab provides you with the following information:
Column | Description |
---|---|
Path | The path the component is located in. |
Function Name | The name of the functions within the selected library. |
Component | The name of the component that it is referenced in. |
To display which components are using a particular function:
- Open the Shared JavaScript Libraries manager.
- Select a function in the Library Manager panel.
- Select the Show Uses button (or Show Uses in the right-click menu) to display the function's uses in the Show Uses tab in the Information panel of Rhapsody IDE.
- To view or edit the configuration properties of a component using the JavaScript function:
- Double-click on the component path.
- Or alternatively, from the right-click menu, select Open Properties.
- Select the Close button to close the dialog.
Validating Functions
You can manually verify whether a function is syntactically correct through the Shared JavaScript Libraries manager. This check, however, does not determine whether the function is contextually correct.
To validate a function:
- Open the Shared JavaScript Libraries manager.
- Select a function panel.
- From the Library Manager panel, check out the library the function is in.
Select the function and select Validate Function in the right-click menu to display the Validation Result dialog.
If there are:
No validation errors, a success message is displayed:
Otherwise, a validation report is displayed:
- Select the Close button to close the dialog.
Code Editor
The Code Editor enables you to inspect, write and edit JavaScript functions. You can open multiple functions at a time which appear in their own tab:
Braces Outlining
Braces enclosed code block are outlined and can be expanded and folded.
Supported Shortcuts
The Code Editor supports the following shortcuts:
Shortcut | Description |
---|---|
Ctrl+Z |
Undo |
Ctrl+Y |
Redo |
Ctrl+A |
Select All |
Ctrl+L | Delete current line |
Ctrl+C |
Copy |
Ctrl+D |
Duplicate current line |
Ctrl+F | Find |
Ctrl+H | Replace |
Ctrl+V |
Paste |
Ctrl+T |
Switch the current line position with the previous line position |
Ctrl+G |
Go to line |
Ctrl+Q |
Block comment |
Ctrl+Shift+Q |
Block uncomment |
Ctrl+mouse wheel button |
Zoom in and Zoom out |
Built-in Context Menu
To display the built-in context menu, right-click in the editor’s pane to activate context menu:
Auto-complete Support
Non-contextual auto-complete support. Basic auto-complete is supported and it includes all JavaScript keywords, Rhapsody built-in functions, and all shared JavaScript functions/libraries.
To activate the auto-complete, press Ctrl+Space. Initially, the auto-complete list will be sorted alphabetically, it will be narrowed down while typing in. Pressing tab to select the current best-matched keyword and the auto-complete will finish.
It also includes words that have been used in the current document. All words that have been used will be included in the auto-complete list.
Calling Shared JavaScript Functions
You can call the shared JavaScript functions from all the components that execute JavaScript code. For example, JavaScript filters, JavaScript conditional connectors, Web Service Client communication points, and so on. However, you cannot check in and check out libraries, within lockers, for which you do not have the Edit permission. This safety mechanism has been built in to prevent users from accidentally modifying existing behavior.
For example, in order to call the function myFunc
in the library MyLib
, use the built-in function require()
in your JavaScript code as follows:
var mylib=require("MyLib"); var result=mylib.myFunc(parameter1, parameter2);
You must call require()
for every library you want to use.
Naming Conventions
- Function names are case sensitive, for example: "f1" and "F1" are two different valid names.
- Function names must begin with a letter, underscore or dollar sign.
- Names must not be:
- JavaScript built-in objects, properties, and methods, for example: Math, Number, String.
- Java objects and properties, for example:
getClass
,java
. - Windows Reserved Words, for example: alert, focus, form.
- HTML Event Handlers, for example:
onblur
,onclick
,onfocus
. - Rhapsody JavaScript objects, for example:
getCounter
,dataMap
,getLookupTable
.
- Names can contain letters, digits, underscores, and dollar signs.
- Local variables within functions must not:
- Be declared with the same name as Rhapsody variables or variables declared within a JavaScript filter.
Configuration Properties
Property | Description |
---|---|
JavaScriptService.maximumInterpreterStackDepth |
The maximum stack depth (in terms of number of call frames) allowed in a single invocation of the interpreter. If the set depth is exceeded, the interpreter throws an EvaluatorException in the script. Defaults to |
JavaScriptService.sharedJSLibraryCacheSize |
The cache size of shared JavaScript library in memory.
Defaults to |