plexus-ui-engine 0.2.4

The plexus-ui engine — signals, live() over Plexus streams, the view tree over a renderer, Rhai folds, sections, hot-swap
Documentation
//! FRAME-12: **the module contract** — what every profile implements and
//! the host mounts: `mount(target, { props, bus }) → { update(props),
//! destroy() }`. In the page a module is an ES module (`esm/1` written by
//! hand, `svelte/1` from FRAME-13) the host imports from its version's
//! `components/<name>.js` and wraps ([`crate::entry`]'s `JsModule`); the
//! rhx runtime (`rhx/1`, the tree and the folds) is the host's own arm of
//! the same lifecycle in [`crate::swap`] — mounted, updated, swapped,
//! fallen back and destroyed by the same rules.

use crate::bus::Member;
use crate::tree::Renderer;
use serde_json::{Map, Value};

/// The profile of the tree-and-Rhai runtime; a manifest entry that names
/// no profile is one.
pub const RHX: &str = "rhx/1";

/// A component's code, ready to mount.
pub trait Module<R: Renderer> {
    /// Draws into `target` with `props`, speaking through `bus`; a module
    /// that throws is refused with its words (and leaves `target` empty).
    fn mount(&self, target: &R::Node, props: &Map<String, Value>, bus: Member) -> Result<Box<dyn ModuleInstance>, String>;
    /// FRAME-30: its sheet's text — what the module exports as `css` (a
    /// svelte/1 module's compiled `<style>`); none when it has none.
    fn css(&self) -> Option<String> {
        None
    }
}

/// A mounted module.
pub trait ModuleInstance {
    /// New props: a route to the same component with other params.
    fn update(&mut self, props: &Map<String, Value>);
    /// Takes it out: its DOM, its subscriptions, its listeners.
    fn destroy(self: Box<Self>);
}