Most components inside the scripts are implemented as JavaScript prototype classes.
To allow an easier understanding of the code and to be more inline with the Phoenicis application implementation classes should be implemented using the new ECMAScript 2015 syntax.
Structure
A class defined with this newer syntax has the following structure:
class ClassName extends ParentClassName {
constructor(<arguments>) {
super(<super-arguments>);
// object initialization
}
foo(<arguments>) {
// method body
return <result>;
}
bar() {
// method body
}
}
Where:
ClassNameis the unique name of the classParentClassNameis the name of the parent class (this is optional)constructor(...)is the constructor method of the class, which is called whenever an object of the class is instantiated via thenewkeywordsuper(...)calls the constructor method of the parent classfoo(...)andbar(...)are prototype function definitions
Example
class ShortcutReader {
constructor() {
// do nothing
}
/**
* sets shortcut
* @param {string} shortcut shortcut
* @returns {void}
*/
of(shortcut) {
const shortcutContentParsed = JSON.parse(shortcut.script);
if (shortcutContentParsed.type == "WINE") {
this.runner = new WineShortcutReader(shortcut);
}
}
/**
* returns container of shortcut
* @returns {string} container
*/
get container() {
return this.runner.container();
}
/**
* runs shortcut
* @param {array} userArguments arguments
* @returns {void}
*/
run(userArguments) {
this.runner.run(userArguments);
}
/**
* stops running shortcut
* @returns {void}
*/
stop() {
this.runner.stop();
}
/**
* uninstalls shortcut
* @returns {void}
*/
uninstall() {
this.runner.uninstall();
}
}