API is divided into four groups. Each group has different characteristics and usages.
Now let's find out the information of each API group to acquire your purpose.
Classes
If you want, the source code can be compatible with Dart-Platform (it means that you can call API and UI can appear in Dart-Platform), you must use Class API such as Base Module, Module Screen, etc. Then, wrap it together suitably and call the method corresponding to Class API. All the actions will generate the source code, which can run on Dart-Platform.
Class includes many properties such as Interface API, Static,… Each Class API has different usages and functions. For easy understanding, please read the below Sample carefully:
Sample: Base Module
An Abstract Class is to be inherited from the module package's Main Class (level 1). DART-Platform's system retrieves an appropriate module's component that requests a Message through this Class. Therefore, the module package must support one Main Class (level 2) inherited from this Abstract Class. The Main Class (level 2) should be implemented in the main script file, which is defined at the 'main' tag of manifest.json.
Because Dart-Suite uses the Message system that is defined in the BaseModule Class, MyModule, which is the Main Class, must inherit BaseModule.
This method is called to retrieve an appropriate ModuleService component about the Message by the system. The method can be called by only system.
Parameters
componentId: string
A component uses to retrieve a component.
Returns
null | typeof ModuleService
Note
A class that is inherited from the ModuleService
onModulePackageInstalled
Command
CODE
onModulePackageInstalled(): void
Definition
This method is called only when the module package is first installed. This method should be overridden and implemented if any jobs are needed after installing the module package. The method can be called by only system.
This method is called when the module package is updated. If any jobs are needed after updating the module package, this method should be overridden and implemented code. The method can be called by only system.
Parameters
oldVersion: string
A module package version before it was updated.
newVersion: string
A module package version after it has been updated.
Returns
void
Below is the complete source code defined for Class BaseModule:
Source code
CODE
export abstract class BaseModule {
/**
* Module package Info
*
* @api-version 1
* @user
*/
readonly packageInfo: IModulePackageInfo;
/**
* A constructor to instantiate {@link BaseModule}.
*
* @api-version 1
* @system
*/
constructor(packageInfo: IModulePackageInfo) {
this.packageInfo = packageInfo;
logger.debug(`BaseModule (${packageInfo.packageName}) is instantiated.`);
}
/**
* This method is called to retrieve an appropriate {@link ModuleScreen} component about the {@link Message} by system.
* The method could be called by only system.
*
* @param componentId A component id to retrieve a component.
* @return An object that is consists of a class which is inherited the {@link ModuleScreen} and CSS file's relative path array that are should be loaded at HTML.
*
* @api-version 1
* @system
*/
getModuleScreen(componentId: string): typeof ModuleScreen | null {
return null;
}
/**
* This method is called to retrieve an appropriate {@link ModuleService} component about the {@link Message} by system.
* The method could be called by only system.
*
* @param componentId A component id to retrieve a component.
* @return A class which is inherited the {@link ModuleService}.
*
* @api-version 1
* @system
*/
getModuleService(componentId: string): typeof ModuleService | null {
return null;
}
/**
* This method is called only when the module package is first installed.
* If there is any jobs which are need to do after install the module package, then this method should be overridden and implement code in the method.
* The method could be called by only system.
*
* @api-version 1
* @system
*/
onModulePackageInstalled(): void {
// empty
}
/**
* This method is called when the module package is updated.
* If there is any jobs which are need to do after update the module package, then this method should be overridden and implement code in the method.
* The method could be called by only system.
*
* @param oldVersion A module package version before it was updated.
* @param newVersion A module package version after it has been updated.
*
* @api-version 1
* @system
*/
onModulePackageUpdated(oldVersion: string, newVersion: string): void {
// empty
}
/**
* Call this when system is need to render a screen component that is included in the module.
* It is needed to avoid 'Minified React error #321' problem.
* The method could be called by only system.
*
* @return The ReactDOM class that is imported in the module package.
*
* @api-version 1
* @system
* @hidden
*/
readonly getReactDom = () => {
return ReactDOM;
};
}
There are many Interfaces, each of which serves different purposes (move the robot, get information from the robot, etc.). In each Interface, there will have methods.
To get your goal about the Interface ButtonInterface, you can read the Sample as follows: