Skip to content

mountAll

The API for mountAll(); Ornata’s declarative API for initializing components from the HTML.

import { mountAll } from 'ornata';
const { mountAll } = window.Ornata;
const instances = mountAll({
Counter,
Disclosure,
});

mountAll() looks for elements with a data-ornata attribute:

<section data-ornata="Counter"></section>
<section data-ornata="Disclosure"></section>

The attribute value must match a key in the constructor map you pass to mountAll().

Calling mountAll() returns an array of mounted instances.

const instances = mountAll({
Counter,
Disclosure,
});
  • roots are selected with document.querySelectorAll("[data-ornata]")
  • each matching constructor is validated with isComponent()
  • each matching root is mounted with component.mount(rootElement)
  • the data-ornata attribute is removed after mounting

See Mounting Instances for a fuller guide.