Component Instance
When you mount a component, Ornata returns a component instance.
That instance becomes the integration point between the component and surrounding page code.
const instance = Counter.mount(root);const instance = Counter.mount(root);Instance shape
Section titled “Instance shape”The public instance currently exposes:
rootstatedispose()addStateListener()
root is the resolved root element the component was mounted on.
state is the public reactive state object.
Updating writable public properties triggers the component update flow.
Properties marked private or readonly in state options are protected from external writes.
When a public state write succeeds, Ornata validates the new value, updates computed values, re-runs render callbacks, calls matching watch callbacks, and notifies state listeners.
dispose()
Section titled “dispose()”dispose() unmounts the instance and runs cleanup behavior, including:
- update cleanup
- state listener cleanup
lifecycle.unmount()
addStateListener()
Section titled “addStateListener()”Use addStateListener() to subscribe to a specific state property.
const cleanup = instance.addStateListener("count", (event) => { console.log(event.newValue);});const cleanup = instance.addStateListener("count", (event) => { console.log(event.newValue);});The listener receives:
{ property, newValue, oldValue, target,}{ property, newValue, oldValue, target,}The method returns a cleanup function that removes the listener.
Use this when code outside the component needs to observe public state changes.
For the conceptual difference between this and watch, see State Listeners and Watchers.
Constructor helpers
Section titled “Constructor helpers”The component constructor also provides instance-management helpers:
mount(root, initialState?)getInstance(root)findInstance(root)unmount(root)
Use getInstance() when absence should throw, and findInstance() when absence is an expected branch.
For a fuller walkthrough, read Instances and Mounting.