Skip to main content

Module plugin

Module plugin 

Source
Expand description

A formal plugin API for AppFront applications (Phase 4 / #47).

A Plugin is a self-contained unit of cross-cutting functionality that an app registers at startup. It has a typed state S (shared via the existing Context mechanism) and a set of hooks that run at well-defined points in the app lifecycle: before/after the tree is built, and around each render. This gives apps an extension point without baking backend-specific fields into UITree.

struct Analytics;
impl Plugin for Analytics {
    type State = ();
    fn on_render(&self, _: &PluginCtx<Self::State>) {
        // ... count renders ...
    }
}

let mut registry = PluginRegistry::new();
registry.register(Analytics);
registry.run_render_hooks();

The API is backend-agnostic: a plugin only ever sees lifecycle events and the shared app state, never a DOM/canvas/TUI handle, so the same plugin works on every backend.

Structs§

PluginCtx
A plugin’s read-only view of app + plugin state during a hook.
PluginRegistry
Holds every registered Plugin and runs their hooks at the right times.

Traits§

Plugin
A plugin: a named, self-contained extension with typed state.

Functions§

context_for_plugin
Convenience: provides a plugin’s state to a subtree as a Context so descendant components can read it.