Skip to content

crate

weft_core

Weft core: components, rendering, diffing and the accessibility tree.

Everything here is platform independent; weft-web provides the browser Host.

Modules

  • a11y

    The semantic layer: an accessibility tree computed from the virtual tree.

  • decls

    A template's declarations at run time: state as signals, let as memos, on handlers as pure transitions, load as data that follows its request, and timers.

  • effects

    Requests for templates: load declarations and the request commands (get, post, put, patch, delete) in handlers.

  • eval

    Evaluating template expressions against a scope.

  • html

    Mapping DSL elements to HTML: tags, attributes, and string rendering (used for server-side rendering and by the DOM host).

  • markdown

    A small Markdown → virtual node renderer for content-heavy pages (markdown(source: post.body) in templates).

  • report

    Warnings for the developer: a template that did something it probably didn't mean, or a component given the wrong shape of data.

  • router

    Path matching for client-side (hash) routing.

  • routes

    File-based routes: the table weft-build generates from app/.

  • scene_bridge

    Converts canvas2d / scene3d element subtrees into graphics data.

  • scene_classes

    Tailwind classes on 3D objects: the utilities that mean something for an object, plain or under hover:, active: (pressed) and focus: (its keyboard proxy focused).

  • style

    Tailwind CSS for rendered trees (server-side rendering / prerendering). In the browser, weft-web generates the same CSS just in time.

  • timers

    Time for templates' timers (every, after, every frame).

  • window

    Window events for templates' @event: handler declarations (@resize: measure, @keydown: press(event.key)).

Structs

  • App

    A mounted application.

  • Component

    A reusable UI unit: a template plus a setup function.

  • Context

    Values components provide to their descendants (see [Props::provide] and [Props::context]).

  • Emitter

    Emits a component's events (see [Props::emitter]).

  • Event

    A UI event. Hosts fill in what they know; handlers bound inside a for loop also receive the loop index and item.

  • EventHandler

    An event name bound to a handler. Equality is by handler identity.

  • Instance

    A mounted component: its props, scope, owned effects and child instances.

  • MemoryHost

    An in-memory host that mirrors the tree by applying patches. Clones share state, so a test can keep one clone and give another to [App::mount].

  • Props

    The attributes and event handlers a parent passes to a component. Reads are reactive, so derived values update when the parent re-renders.

  • Registry

    Components available to templates by name.

  • RenderError

    An error while evaluating a template against a scope.

  • Scope

    An immutable, cheaply clonable set of bindings with an optional parent.

  • VElement

    An element in the rendered tree: its tag, attributes, event handlers and children.

Enums

  • Binding

    What a name in a scope refers to.

  • Patch

    A single change. Paths index from the root list; Append/Truncate paths name the parent (empty = root list).

  • Value

    A runtime value. Templates are dynamically typed; Rust state is converted into Values at the scope boundary.

  • VNode

    A node in the rendered tree: an element, or text.

Traits

  • Host

    A rendering backend.

Functions

apply

pub fn apply(roots: &mut Vec<VNode>, patches: &[Patch])

Apply patches to a tree. Patches with paths that don't resolve are ignored.

compare_values

pub fn compare_values(lhs: &Value, op: CmpOp, rhs: &Value) -> bool

Evaluate lhs op rhs: numerically when both sides are numbers (or numeric strings), otherwise by text.

diff

pub fn diff(old: &[VNode], new: &[VNode]) -> Vec<Patch>

Compute the patches turning old into new.

find_in

pub fn find_in<'a>(roots: &'a [VNode], path: &[usize]) -> Option<&'a VNode>

Resolve a path whose first index selects a root node.

find_in_mut

pub fn find_in_mut<'a>(roots: &'a mut [VNode], path: &[usize]) -> Option<&'a mut VNode>

The node at path among roots (the first index picks the root), to change it.

prevent_default

pub fn prevent_default()

Ask the host to cancel the browser's default action for the event being handled: what a handler's prevent() step does.

render

pub fn render(template: &Template, scope: &Scope, registry: &Registry) -> Result<Vec<VNode>, RenderError>

Render a template once. Nested components are created fresh on every call; use an Instance (or App) to keep their state.

take_prevented

pub fn take_prevented() -> bool

Whether a handler asked to cancel the default action since the last call, clearing it. Hosts call it before dispatching an event (to start clean) and after (to cancel it).

Type aliases

Dispatcher

pub type Dispatcher = Rc<dyn Fn(&[usize], &Event) -> bool>;

Routes a host event to the handlers at a virtual-node path.

Handler

pub type Handler = Rc<dyn Fn(&Event)>;

An event callback.

ScopeFunction

pub type ScopeFunction = Rc<dyn Fn(&[Value]) -> Value>;

A function templates call (see [Scope::function]).

Re-exports