PluginBuilder
A PluginBuilder
is a core service used by plugins to perform initial setup and configuration logic when the
micro-radiant starts. Builders allow plugins to run asynchronous tasks, register services, and prepare the environment
before the main editor interface is rendered.
What is a Plugin Builder?
A PluginBuilder
is a class that implements the PluginBuilder
interface. It serves as the entry point for a plugin's
build-time logic. This is the ideal place to:
- Initialize background services.
- Perform complex data fetching or processing.
- Register services and providers that the rest of your plugin will use.
The build()
Method
Every PluginBuilder
must implement an asynchronous build()
method.
interface PluginBuilder {
/**
* Performs setup logic for the plugin.
* This method is called once when the plugin is loaded.
*/
build(): Promise<PluginBuildResult>;
}
interface PluginBuildResult {
/**
* An array of Angular providers to be added to the editor's
* dependency injection context.
*/
providers: Provider[];
}
-
Asynchronous Execution: The
build()
method is asynchronous (Promise<PluginBuildResult>
). This allows you to perform time-consuming tasks without freezing the browser. The application will wait for all builders to complete before the editor is rendered, guaranteeing that all plugin dependencies and services are ready. -
Providing Services: The
build()
method must return aPluginBuildResult
object. This object contains an array ofProvider[]
, which are automatically added to the application's dependency injection context. This is the standard way for a plugin to make its services, components, and other dependencies available to the rest of the application. -
Setting up Background Processes: You can use the
build()
method to start long-running tasks, such as subscribing to data streams or initializing web workers, ensuring they are active from the moment the application loads.
See Providers for a list of injection tokens that can be used to provide functionality.
Providing a Plugin Builder
To register a PluginBuilder
with your plugin, you must declare it within an ExtensionModule
. Use the static forExtension()
method and pass your builder class in the builders
array.
import { NgModule } from '@angular/core';
import { ExtensionModule } from '@nsx/ngx-glint-models';
import { MyPluginBuilder } from './my-plugin-builder.service';
@NgModule({
imports: [
ExtensionModule.forExtension({
// Register MyPluginBuilder to be run when this extension is loaded.
builders: [
MyPluginBuilder
]
})
]
})
export class MyExtensionModule {}