Builder API
Creating a hierarchy of elements is often awkward and cumbersome when working with Elemental. Even simple structures like
lead to a vast amount of Document.createElement()
and chained Node.appendChild()
calls. With Elemento, creating the above structure is as easy as
References
When creating large hierarchies of elements, you often need to assign an element somewhere in the tree. Use an inline assignment together with element()
to create and assign the element in one go:
Classes and Interfaces
The builders in Elemento are of one of the following classes:
The builders get their features solely by implementing specific interfaces. These interfaces contain default methods to manipulate the encapsulated element in a specific way.
The interface names follow the pattern [HTML|MathML|SVG]Element<Scope>Methods
. Some examples are
If you only use Elemento to create a DOM tree quickly and easily, you won't most likely come into touch with these method interfaces. However, if you want to create your own builders, the interfaces come in very handy. You can have very fine-grained control over which methods your builder should provide. And since these methods are defined as default methods in interfaces, you are free to mix and match the interfaces across different builders without worrying about multiple inheritance.
Last updated