Skip to content

feat: add plugin lifecycle hooks for load and dispose#540

Merged
tbouffard merged 2 commits into
mainfrom
feat/add_plugin_new_lifecycle_steps
Jun 30, 2026
Merged

feat: add plugin lifecycle hooks for load and dispose#540
tbouffard merged 2 commits into
mainfrom
feat/add_plugin_new_lifecycle_steps

Conversation

@tbouffard

Copy link
Copy Markdown
Member

What

Extend the plugin system with four new optional lifecycle hooks on the Plugin interface, so plugins can react to the BpmnVisualization lifecycle without any client code wiring:

  • onDispose: called when the instance is disposed, before the underlying resources are released.
  • onBeforeLoad: called at the start of each load, before the BPMN source is processed.
  • onLoadSuccess: called after a load has succeeded.
  • onLoadError(error): called with the thrown error when a load fails, before the error is rethrown to the caller.

Why

Until now the only lifecycle hook was onConfigure (post-construction). Plugins had no way to run logic around load and dispose, which are the two key moments where a plugin typically needs to set up, refresh, or release resources. These hooks fill that gap while keeping everything opt-in: a plugin implements only the hooks it needs, and plugins without a given hook are simply skipped.

How

  • BpmnVisualization overrides dispose() and load() and notifies every registered plugin through a shared forEachPlugin helper.
  • load() wraps the delegation to super.load() in a try/catch: on failure it calls onLoadError then rethrows, so callers still observe the error; onLoadSuccess only runs on the success path. onBeforeLoad always runs first.
  • noImplicitOverride is enabled in tsconfig to enforce the override modifier on the new overrides.

Naming

onLoadSuccess is named for the success-only contract (it is intentionally skipped on error), pairing clearly with onLoadError. onLoadError receives the caught error so plugins can react to what failed.

Documentation

The README documents all five hooks and adds a worked example showing how to pass options to a plugin via onConfigure using module augmentation of GlobalOptions, namespacing properties under a per-plugin object to avoid name clashes.

Tests

Added coverage for each hook: that the hook fires the expected number of times, that plugins missing the hook are ignored without error, and the success/error exclusivity (success does not trigger onLoadError, and a failing load still triggers onBeforeLoad while skipping onLoadSuccess).

Extend the Plugin interface with four optional lifecycle hooks so plugins can react to the BpmnVisualization
lifecycle without any client code wiring:
- onDispose: called when the instance is disposed, before the underlying resources are released
- onBeforeLoad: called at the start of each load, before the BPMN source is processed
- onLoadSuccess: called after a load has succeeded
- onLoadError: called with the thrown error when a load fails, before the error is rethrown

BpmnVisualization overrides dispose() and load() to notify every registered plugin through the forEachPlugin helper.
load() wraps the delegation in a try/catch so onLoadError fires on failure and onLoadSuccess only on success. Enabling
noImplicitOverride in tsconfig enforces the override modifier on these new overrides.

Document the hooks in the README, including how to pass options to a plugin via onConfigure using module augmentation
of GlobalOptions, namespacing properties under a per-plugin object to avoid name clashes.
@tbouffard tbouffard added the enhancement New feature or request label Jun 30, 2026
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

♻️ Preview destroyed

PR preview ♻️ Destroyed ♻️ Destroyed
🔗 Preview https://process-analytics-bpmn-visualization-addons-demo-pr-540.surge.sh (already destroyed)
📝 Commit3f6c1c3
🪵 LogsView logs

🤖 Powered by surge-preview

Lock the onLoadError contract by checking the hook is called with the caught error, not just that it is invoked.
@sonarqubecloud

Copy link
Copy Markdown

@tbouffard tbouffard changed the title feat: add dispose and load lifecycle hooks to the plugin system feat: add plugin lifecycle hooks for load and dispose Jun 30, 2026
@tbouffard tbouffard merged commit 58a2446 into main Jun 30, 2026
10 checks passed
@tbouffard tbouffard deleted the feat/add_plugin_new_lifecycle_steps branch June 30, 2026 10:27
@tbouffard tbouffard linked an issue Jun 30, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add Plugin cleanup support when BpmnVisualization is disposed

1 participant