Plugin lifecycle
A plugin is an ES module, usually bundled into a single JavaScript file. It exports two functions, both returning a Promise:
initialize(api)starts the plugin.dispose(api)stops it and undoes everythinginitializedid.
import type { DemoShellApi, BrokerDisposableHandler } from "@uxland/harmonix-demo-shell";
let subscription: BrokerDisposableHandler | undefined;
export const initialize = async (api: DemoShellApi) => {
await api.regionManager.registerMainView({
id: "orders",
factory: async () => document.createElement("orders-list"),
});
subscription = api.broker.subscribe("user:changed", () => console.log("Reload the orders"));
};
export const dispose = async (api: DemoShellApi) => {
subscription?.dispose();
await api.regionManager.removeView(api.regionManager.regions.main, "orders");
};
A plugin's lifecycle has two parts:
- Offline lifecycle: development, maintenance and distribution of the plugin.
- Online lifecycle: what happens to the plugin inside a running shell.
Offline lifecycle
- Creation
- Development and testing
- Publication
- Maintenance
- Updates
- Deprecation
- Deactivation
Phases 1, 2 and 4 happen locally. Phases 3, 5, 6 and 7 involve the Plugin Store, which should support all of them. Some Plugin Stores also support a progressive rollout in phase 3: a new version starts with a subset of users until it is mature enough. This is a capability of the Plugin Store, not of Harmonix itself.
Online lifecycle
Loading
ordersviews in the regions
alertsviews in the regions
insights
importer()EvaluationmoduleInitializationinitialize(api)Renderingfactory()Disposaldispose(api)imported plugin: orders
imported plugin: insights
initialized plugin: orders
imported plugin: alerts
Failed to load plugin insights: Error: settings not found
initialized plugin: alerts
// insights failed and is isolated: orders and alerts carry on
- Loading. The shell calls the
importer()of the plugin'sPluginDefinition. Usually this is a dynamicimport()of the plugin's URL in the Plugin Store, or of a local module during development. - Evaluation. The browser evaluates the module, which exposes
initializeanddispose. - Initialization. Harmonix calls
initialize(api)with an API instance created for this plugin. All plugins are initialized in parallel. If one throws, the error is logged and the other plugins carry on. - Rendering. The registered views appear in their regions. Each view's
factoryruns when its region needs the element. - Disposal. The shell calls
dispose(api). This function is required, and it must undo everything: remove views, dispose broker subscriptions and request handlers, stop timers, and release any other resources.
See Building a shell for the shell side of this process.