Advanced / Composition · guide
Plugins (painter.plugins, painter.use)
Current Apexify.js 6.0.0 documentation for Plugins (painter.plugins, painter.use).
Apexify.js exposes two related extension mechanisms:
painter.plugins(PluginHost) — a name → API-object registry.await painter.use(plugin)— transactional plugin installation with one installation per plugin name.
ApexPainter.use is asynchronous. Always await it. The method resolves to the painter instance only after plugin.install(host) has completed.
painter.plugins registry
Registry contract:
use(name, api)validates the name and rejects duplicate API names withApexifyPluginError.get<T>(name),has(name),list()inspect registered APIs.remove(name)deletes an API entry.isInstalled(name),listInstalled()inspect completedApexifyPlugininstallations.
API names and plugin names must be non-empty identifier-like strings.
await painter.use(plugin)
Lifecycle and duplicate semantics
- Calling
painter.use()twice with the sameplugin.nameis rejected. - A second same-name call is also rejected while the first installation is still pending.
- Different plugin installations are serialized so plugin transactions do not overlap.
- A failed plugin name is released after cleanup, so the application may retry that plugin later.
- The current lifecycle is install-only. Apexify.js does not provide plugin uninstall/teardown hooks.
Failure rollback
PluginHost uses an async-context transaction around plugin.install(host). If install() throws or rejects:
- API registrations made through
host.plugins.use(...)inside that plugin installation are removed. - Pre-existing PluginHost APIs removed by the failing plugin are restored.
- Unrelated application registry writes that happen concurrently while the plugin is awaiting are preserved.
- The plugin is not marked installed.
- The caller receives
ApexifyPluginErrorwith the original error as its cause.
Rollback is intentionally limited to PluginHost registry mutations performed in the plugin installation context. Apexify.js cannot automatically undo arbitrary external side effects performed by plugin code (files, network calls, timers, mutations to unrelated application state). Plugins should perform irreversible side effects only after their own prerequisites are known to have succeeded, or provide their own compensation logic.
Type safety
ApexifyPlugin<T> types the installation host. PluginHost.get<T>() lets consumers recover the registered API type at the lookup site.
When to use which
| Goal | Tool |
|---|---|
| Attach a plain named helper object | painter.plugins.use(name, api) |
| Run one-time synchronous or asynchronous setup | await painter.use(plugin) |
| Need automatic uninstall/teardown | Not provided; manage that lifecycle in your application/plugin |