Plugin

View source

Base lifecycle contract for a plugin that contributes configuration to an App.

Register instances with App#registerPlugin. Override Plugin#register to stage configuration. Override Plugin#finish for final setup, Plugin#requires to declare required plugin IDs, or Plugin#name to provide a custom identity. The base lifecycle methods are no-ops, the base dependency list is empty, and the default identity is the concrete plugin class’s type ID.

Examples

import { App, Plugin } from '@wimaengine/app'

class Settings {}
class DefaultWorld {}

class SettingsPlugin extends Plugin {
  register(app) {
    app
      .setWorld(DefaultWorld)
      .defaultWorld(DefaultWorld)
      .setResource(new Settings())
  }
}

new App()
  .registerPlugin(new SettingsPlugin())
  .setRunner(() => {})
  .run()

Constructor


constructor()

Methods


register(_app: App): void

View source

Configures the app during the registration phase of App#run.

PluginRegistry calls this hook for each registered plugin in insertion order, before it validates any Plugin#requires IDs. A hook can use the app’s registration methods to configure worlds and resources, install component hooks, and stage schedules with execution callbacks for the app runner. It can also call App#registerPlugin to add a nested plugin. The registry continues through plugins added during this pass, and those plugins also reach the later Plugin#finish pass. Return values are ignored.

Parameters

NameDescriptionDefault
_app

App being configured.

—

Returns

This hook’s return value is ignored.

finish(_app: App): void

View source

Performs final setup after registration and dependency validation.

PluginRegistry calls this hook in insertion order after Plugin#requires checks pass, but before App#run applies queued resources, aliases, and component hooks, builds the scheduler, or invokes the runner. Plugins added during finish are visited later in the finish pass, but their dependencies were not part of the earlier validation pass. Use this hook for setup that depends on all registration hooks having run; return values are ignored.

Parameters

NameDescriptionDefault
_app

App being finalized.

—

Returns

This hook’s return value is ignored.

requires(): TypeId[]

View source

Returns plugin IDs that must already be registered before finalization.

App#run asks PluginRegistry to validate every returned ID after all registration hooks complete and before any finish hook runs. A missing ID causes run to throw; IDs do not cause plugins to be installed, and this list does not reorder plugin hooks. The base implementation has no dependencies.

Returns

Required plugin type IDs.

name(): TypeId

View source

Returns this plugin’s identity used by PluginRegistry.

The default implementation returns typeid(this.constructor). Override it when a plugin has multiple valid instances that need distinct identities, such as a generic plugin keyed by a configured constructor. The returned ID is checked when App#registerPlugin adds the plugin; registering a duplicate ID throws instead of replacing the existing instance.

Returns

Plugin identity used for duplicate detection and dependency lookup.