Instances and Mounting
Ornata supports both declarative page bootstrap and direct imperative control.
That balance is useful in HTML-first environments where some components are declared in markup and others are managed by surrounding integration code.
Mounting a component
Section titled “Mounting a component”You can mount a component with either an element or a selector.
const instanceA = Counter.mount(document.querySelector("[data-counter]"));const instanceB = Counter.mount("[data-counter]");const instanceA = Counter.mount(document.querySelector("[data-counter]"));const instanceB = Counter.mount("[data-counter]");You can also pass initialState at mount time.
Getting an existing instance
Section titled “Getting an existing instance”Use getInstance() when you expect the instance to exist and want absence to throw.
const instance = Counter.getInstance("[data-counter]");const instance = Counter.getInstance("[data-counter]");Use findInstance() when absence is a normal branch.
const maybeInstance = Counter.findInstance("[data-counter]");const maybeInstance = Counter.findInstance("[data-counter]");Unmounting and disposal
Section titled “Unmounting and disposal”You can unmount from the constructor:
Counter.unmount("[data-counter]");Counter.unmount("[data-counter]");Or dispose from the instance:
const instance = Counter.mount("[data-counter]");instance.dispose();const instance = Counter.mount("[data-counter]");instance.dispose();Root lookup safeguards
Section titled “Root lookup safeguards”When you pass a selector, Ornata resolves the root for you.
If the selector does not match an element, Ornata throws.
If the input is not a valid element or selector, Ornata also throws.
That makes the mounting API stricter and easier to trust.
A good mental model
Section titled “A good mental model”mount()creates an instancegetInstance()retrieves an existing one and throws if missingfindInstance()retrieves an existing one or returnsnullunmount()removes an instance by rootdispose()removes the current instance directly