Instance lifecycle

Mounting, lazy readiness, subscriptions and destroy.

1.0.0-beta.6 · Local build · desktop

One instance per target

Mount after your target exists in the browser. Keep the instance while the application owns that element. Calling the constructor on the server or repeatedly mounting without destruction is incorrect. The core does not require a framework.

Readiness

whenReady covers initial asynchronous Markdown/CSS. whenSourceReady covers loading and mounting the HTML/CSS source interface. Await setContent/setCSS/replaceRange where their operation is asynchronous; do not infer readiness from one event-loop tick.

Cleanup

Destroy is idempotent and releases editor resources, plugin commands, UI and managed listeners. Plugin cleanup errors may yield AggregateError after resources have been released. Your application must abort its own requests and release its external subscriptions.

Async mounts

A dynamic import can resolve after component unmounting. Track disposal before constructing and destroy a newly created instance if ownership has ended. Site demos follow this pattern. Vue/Nuxt, methods.

const editor = new ViText(host, {
  content: '# Начало', contentType: 'markdown', language: 'en'
});
await editor.whenReady();
editor.focus();
const off = editor.on('change', event => console.log(event.revision));
off();
editor.destroy();

Search documentation

No results. Try different words.

All documentation