Globals
The Globals package is a kernel that manages the globals of the application (e.g., window) and uses the globalsHelper to expose an API.
Globals helper
This helper injects to the plugins a set of methods to retrieve these globals.
Note: It is highly encouraged to use this helper whenever a global is needed. It will allow securing the application if needed and it provides a better testing experience by avoiding mocking and un-mocking globals.
getConsole
Gets the Console property of Window object.
Usage
getConsole(): object
Returns
-
Object
A reference to the Console object.
Example
class PluginExample {
constructor({ getConsole }) {
this.console = getConsole();
this.console.log('Hello World');
}
}
getCookies
Gets cookies of the application and parses them.
Usage
getCookies(): object
Returns
-
Object
Cookies.
Example
class PluginExample {
constructor({ getCookies }) {
this.cookies = getCookies();
const { my_cookie } = this.cookies;
}
}
getDocument
Gets the document property of Window object.
Usage
getDocument(): object
Returns
-
Object
A reference to the document contained in the window.
Example
class PluginExample {
constructor({ getDocument }) {
this.document = getDocument();
const { baseURI } = this.document;
}
}
getGlobal
Gets the Global object.
Usage
getGlobal(): object
Example
class PluginExample {
constructor({ getGlobal }) {
this.global = getGlobal();
this.global.alert('Hello World');
}
}
getWindow
Gets the Window object. This function is an alias of getGlobal().
Usage
getWindow(): object
Returns
-
Object
Window object.
Example
class PluginExample {
constructor({ getWindow }) {
this.window = getWindow();
this.window.alert('Hello World');
}
}