Class
PluginRegistry
View sourceInternal registry that tracks plugin instances staged for an App.
Most API users interact with this registry through
App#registerPlugin rather than calling it directly. Each plugin is
identified by the TypeId returned by Plugin#name. The
registry preserves insertion order, rejects duplicate IDs, visits plugins
added during lifecycle passes, and validates declared dependencies before
finalization.
Examples
import { App, Plugin } from '@wimaengine/app'
class ChildPlugin extends Plugin {}
class ParentPlugin extends Plugin {
register(app) {
// The child is appended after the parent during the same pass.
app.registerPlugin(new ChildPlugin())
}
}
new App()
.registerPlugin(new ParentPlugin())
.setRunner(() => {})
.run()
// Both lifecycle hooks visit ChildPlugin after ParentPlugin.Constructor
Properties
list: Plugin[]
View sourcePlugin instances in registration order.
Nested registrations are appended to this array. The
PluginRegistry#register and PluginRegistry#finish loops
continue through those appended entries.
Default: []
names: Set<TypeId>
View sourceType IDs accepted by PluginRegistry#add.
This set is used for duplicate detection and by
PluginRegistry#hasTypeId; it does not contain plugin instances
and does not determine hook order.
Default: ...
parents: Map<TypeId, TypeId>
View sourceParent IDs for plugins registered from another plugin hook.
A child ID maps to the active parent ID. Direct app registrations have no entry. The map is used only to format duplicate-registration traces; it is not used for dependency validation or lifecycle ordering.
Default: ...
stack: TypeId[]
View sourceActive plugin IDs while a lifecycle hook is executing.
PluginRegistry#register and PluginRegistry#finish push
the current plugin before calling its hook and pop it after the hook
returns. The last ID is the parent used when that hook registers another
plugin.
Default: []
Methods
add(plugin: Plugin): void
View sourceAdds a plugin instance in insertion order.
The plugin’s Plugin#name supplies its identity. When called from
an active plugin hook, the current stack entry is recorded as the new
plugin’s parent for duplicate-registration diagnostics. A duplicate ID
throws before the list or ID set is changed.
hasTypeId(pluginId: TypeId): boolean
View sourceChecks whether a plugin ID is registered.
has(pluginId: TypeId): boolean
View sourceAlias for PluginRegistry#hasTypeId used by registry callers.
enter(pluginId: TypeId): void
View sourceMarks a plugin hook as active for nested-registration tracking.
This pushes the ID onto PluginRegistry#stack; it does not
register or validate a plugin by itself.
leave(): void
View sourceLeaves the most recently entered plugin hook.
register(app: App): void
View sourceRuns each plugin’s registration hook in insertion order.
The list is allowed to grow during this pass, so plugins registered from
a running Plugin#register hook are visited later in the same
pass. Each hook runs with its ID on PluginRegistry#stack; this
method does not validate dependencies or run finish hooks.
finish(app: App): void
View sourceRuns each plugin’s finish hook in insertion order.
Plugins added while a finish hook runs are appended and visited later in this same pass. Dependency validation has already happened before this method is called, so plugins added here are not included in that earlier validation pass.
assertDependencies(app: App): void
View sourceValidates the plugin dependencies declared by Plugin#requires.
Every registered plugin is asked for its required IDs, and each ID is
checked through App#hasPlugin. This method does not load missing
plugins, reorder hooks, or interpret dependencies as lifecycle order.
