What to avoid during add-on development
When developing your add-on for eLabNext, there are several pitfalls that should be avoided in the add-on code, besides the standard JavaScript guidelines, of course. JavaScript Code Style Guide
Hard coding sensitive information
Never hardcode sensitive information into the add-on code. If you want to use the eLabSDK API in your add-on, you can make use of the eLabSDK API function, which uses the authentication information from the logged-in user.
If you have an external application that needs authentication, OAuth is a secure method to allow user authentication through login functionality:
If neither option is suitable for your ends, you can also use the add-on configuration option to achieve this:
External dependencies
The add-on code should use pure JavaScript and not depend on external libraries. In previous iterations of the documentation, we exposed code that contained JQuery and Mootools as external tools. See the following example:
These external dependencies should be phased out as add-ons should not depend on external dependencies. If your add-on is still based on these dependencies, the recommendation is to look at the following recipe, which indicates how the same setup can be achieved without their need.
SDK(2) outside the add-on init
SDK functionality has to be placed inside the initialization part of the add-on to ensure all required functionality has been properly loaded before usage. The following example shows a bad and good use case of SDK functionality within an add-on:
var MY_ADDON_IDENTIFIER = {};
// use IIFE style declaration
(function(context) {
let badState = eLabSDK2.getSDKStore().state; // this yields a warning
context.init = function(data) {
let goodState = eLabSDK2.getSDKStore().state; // this yields valid data
}
// This needs to be called to make the add-on active when side loading. When the add-on is added to the Marketplace, this is not needed anymore.
context.init();
})(MY_ADDON_IDENTIFIER);
When the SDK functionality is placed outside of the initialization, as in the badState from the example, a console warning will be shown, and the add-on will not function.
Updated 3 days ago