Component Registry
What are we learning here?
- Using the Component Registry
Every component have at least one component registry with the id "main". You can add more registries
with this.registerRegistry(Id)
. A registry basically predefine component start objects with a
fixed id and target stage. Components can be organized hierarchical.
The main registry can be referenced with this.registry
or more verbose this.getRegistry("main")
.
The idea behind of a component registry is a central point where components will be only registered and not loaded. Other components can reference to this registry and load them if necessary.
A good place to define a registry is of course in the root component. All other compopnents can easily reference to the root component.
The structure of a registry is an object holding component start definition objects in each key. Each start definition object can have additional properties. All of them are optional:
authorization
: Who can start this component (will be discussed later).stage
: The stage id in what the component should be started. If not givenmain
is the default.name
: Visual representation of the component entry.iconHtml
: Visual representation of the component entry.
Remark: name
and iconHtml
overrides the visual representation of the component itself defined in
its manifest (will be discussed later).
{
key1: {
// Start Definition Object with additional Properties
},
key2: {
// Start Definition Object with additional Properties
},
// ... and so on ...
}
If you want to define a subgroup you have to add an object with the property type: "group"
and
optional:
name
: Visual representation of the subgroup.iconHtml
: Visual representation of the subgroup.
All the other properties will be handled as sub entries:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Please note the difference between the key in the registry and the optional id of a component. The id of a component will be defined in its start definition object. You can even define the same component with the same id under different keys:
{
key1: {
id: "the_id",
component: SomeComponent,
name: "Name 1",
iconHtml: "...",
options: {
opt1: "First Value"
}
},
key2: {
id: "the_id",
component: SomeComponent,
name: "Name 2",
iconHtml: "...",
options: {
opt1: "Second Value"
}
},
}
In the example above you can start the component with key1
or with key2
. If the component was
already started just the new options will be passed and the the running component will be fronted.
Implicit type
in each level
When you retreive the registry data with await this.registry.get()
you will see that the
property type
was added into every object. There are three types: root
, group
and
component
. Example:
{
type: "root",
key1: {
type: "component"
},
subGroup: {
type: "group",
}
}
Let us add all our application we have write so far into the main registry of our root component
defined in root.js
. Because such a registry can become very large we will outsource the code in
a separate file:
src/apps.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
We will add our registry object into the main registry of our root component:
src/root.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
We do not see any changes but that will change quickly in the next chapter.