Skip to content

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.

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]");

You can also pass initialState at mount time.

Use getInstance() when you expect the instance to exist and want absence to throw.

const instance = Counter.getInstance("[data-counter]");

Use findInstance() when absence is a normal branch.

const maybeInstance = Counter.findInstance("[data-counter]");

You can unmount from the constructor:

Counter.unmount("[data-counter]");

Or dispose from the instance:

const instance = Counter.mount("[data-counter]");
instance.dispose();

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.

  • mount() creates an instance
  • getInstance() retrieves an existing one and throws if missing
  • findInstance() retrieves an existing one or returns null
  • unmount() removes an instance by root
  • dispose() removes the current instance directly