Comment on page
Use third-party libraries
Every developer learns one of the most important principles of software engineering early in their career: DRY (Don’t Repeat Yourself). Using third-party libraries can save your time as you do not need to develop the functionality that the library provides. Openblocks provides some built-in third-party libraries for common uses, and you can manually import other libraries on demand.
- App-level libraries get loaded only in the app where defined. Plus, app A cannot use libraries that are set up for app B.
Tips you should know before setting up libraries:
- External libraries are loaded and run in the browser.
- NodeJS-only libraries are not supported now.
- URLs of external libraries need to support cross-domain.
- The export of the library must be set directly on the window object, global variables like
var xxx = xxxdo not take effect.
- The external libraries run in a restricted sandbox environment and the following global variables are not available:
Now let's take cowsay as an example and import it at app-level and workspace-level.
Create a JS query and insert code.
You can obtain the same result by calling the
cowsay.say()method in the value of the text component.
Note that the cowsay library is imported at app-level and you can not use it in any other app within your workspace.