About the uiClass library
What is uiClass
?
The uiClass
is an abstract class from which all components are extended. The uiClass
is a low-level class and is rarely used as direct parent for UI components’ classes.
uiClass
source code is <UI_Module_dir>/view/base/web/js/lib/core/class.js
, in the Magento Open Source github repository: app/code/Magento/Ui/view/base/web/js/lib/core/class.js
Commonly used uiClass methods
The uiClass class introduces the architecture of UI components through the following methods:
-
The
extend()
method implements inheritance of UI components. Theextend()
returns new class. Theextend()
method gets a JavaScript object as a parameter, and then extends the base object with the properties and methods of the argument’s object. The properties of the argument’s object have higher priority than base object’s properties. As an example: %componentName%.extend(%JavaScript_extender_object%); -
The
initConfig()
method processes the UI component’s configurations. TheinitConfig()
method gets as a parameter the JavaScript configuration object, which is then merged with the default configuration (declared in the UI Component that calls theinitConfig()
method) and in the parent UI component. This resulting configuration is then set as first level properties in the current UI component instance.As an example:
- The
initialize()
method is called during instantiation. It can be used to add custom functionality executed only once, during component instance creation.
As an example:
- The
_super()
method calls the parent UI component method with the same name as the_super()
method’s caller; if that method does not exists in the parent UI component, then the method tries to find it higher in the inheritance chain. As an example:
Commonly used uiClass properties
The defaults
property declares the list of properties of a UI component’s instance. Also it declares communications between components if needed.
As an example: