Addressing: Creating Multiple Stages
What are we learning here?
- Stages with
this.registerStage(Element,Id,Access)
will set an id for addressing and the access level - Multiple stages can also be created with
this.element.registerStages()
in conjunction with the HTML attributesdata-cc-stage
anddata-cc-stage-access
A component can create as many stages as needed. We are now considering the case where we use a component to define a layout with multiple stages in which several widgets are loaded. We will look now how to build such a layout with the flexbox model.
Furthermore, we want a component to create the stages and the parent component to use them. Therefore we have to mark them as "public" and provide them with an id.
We create a layout based on flexbox and put the file in a new subfolder:
src/demo/apps/stages-flexbox/content.html
Now we create our new component. We have already learned, that we can create a stage with the method
registerStage()
. So we could do here something like:
this.registerStage(this.element.querySelector("[data-role=stage]"), "mario", "public");
this.registerStage(this.element.querySelector("[data-role=stage]"), "luigi", "public");
this.registerStage(this.element.querySelector("[data-role=stage]"), "peach", "public");
this.registerStage(this.element.querySelector("[data-role=stage]"), "daisy", "public");
As you can see that we create a stage with the method this.registerStage()
with two more
arguments. The second argument is an id with which we can later address the stage and the third
argument is the access level which is by default "private". With "public" you specify that this
stage can also be addressed by parent components.
You can simplify the above commands and replace them with only one. The component element offers a
simple method named registerStages()
to convert all elements that have the attributes
data-cc-stage
and optional data-cc-stage-access
into a stage. The value of the attribute
data-cc-stage
is then used as the id of the stage. If available the value of the attribute
data-cc-stage-access
will be used as third argument and should be public
or private
(default).
So we create a canvas component that only loads the template and creates the stages with just some lines of code:
src/demo/apps/stages-flexbox/content.js
We will now load the canvas component you just created itself in a new application component:
src/demo/apps/stages-flexbox/index.js
We load the new application in our root.js
file (just by replacing the previous one):
src/root.js
Now we have a nice application which provide four empty stages.