Skip to main content

Renderer

Trait Renderer 

Source
pub trait Renderer: Clone + 'static {
    type Node: Clone + PartialEq + Debug + 'static;

Show 15 methods // Required methods fn create_element(&self, tag: &str) -> Self::Node; fn create_text(&self, text: &str) -> Self::Node; fn set_attr(&self, node: &Self::Node, name: &str, value: &str); fn remove_attr(&self, node: &Self::Node, name: &str); fn set_text(&self, node: &Self::Node, text: &str); fn insert( &self, parent: &Self::Node, child: &Self::Node, before: Option<&Self::Node>, ); fn remove(&self, parent: &Self::Node, child: &Self::Node); fn listen( &self, node: &Self::Node, event: &str, handler: Rc<dyn Fn(Value)>, ) -> Unlisten; fn marks(&self, root: &Self::Node) -> Vec<Self::Node>; fn attrs(&self, node: &Self::Node) -> Vec<(String, String)>; fn contains(&self, ancestor: &Self::Node, node: &Self::Node) -> bool; fn observe( &self, root: &Self::Node, f: Rc<dyn Fn(Vec<Self::Node>)>, ) -> Unlisten; // Provided methods fn sheet(&self, key: &str, css: &str, on: bool) { ... } fn listen_keys(&self, f: Rc<dyn Fn(&Press) -> bool>) -> Unlisten { ... } fn keys_overlay(&self, groups: Option<&KeyGroups>) { ... }
}
Expand description

What draws: the DOM in the browser, Recording in the tests. Every method takes &self (a handle), as web_sys’s do.

Required Associated Types§

Source

type Node: Clone + PartialEq + Debug + 'static

Required Methods§

Source

fn create_element(&self, tag: &str) -> Self::Node

Source

fn create_text(&self, text: &str) -> Self::Node

A text node holding text (an if’s or each’s anchor is an empty one).

Source

fn set_attr(&self, node: &Self::Node, name: &str, value: &str)

Source

fn remove_attr(&self, node: &Self::Node, name: &str)

FRAME-50: the attribute name taken off node.

Source

fn set_text(&self, node: &Self::Node, text: &str)

Source

fn insert( &self, parent: &Self::Node, child: &Self::Node, before: Option<&Self::Node>, )

child into parent, before before (none: last).

Source

fn remove(&self, parent: &Self::Node, child: &Self::Node)

Source

fn listen( &self, node: &Self::Node, event: &str, handler: Rc<dyn Fn(Value)>, ) -> Unlisten

Calls handler with the event’s payload whenever event fires on node (window-<event>: on the window, while node is mounted). UI-10: the answer takes the listener away again — the tree calls it when the node’s block goes, so no closure outlives its component.

Source

fn marks(&self, root: &Self::Node) -> Vec<Self::Node>

FRAME-18: the elements under root (itself left out) carrying data-slot — a layout’s section marks — in document order.

Source

fn attrs(&self, node: &Self::Node) -> Vec<(String, String)>

FRAME-18: an element’s attributes, (name, value) each.

Source

fn contains(&self, ancestor: &Self::Node, node: &Self::Node) -> bool

FRAME-18: whether node is ancestor or under it.

Source

fn observe(&self, root: &Self::Node, f: Rc<dyn Fn(Vec<Self::Node>)>) -> Unlisten

FRAME-18: calls f after each batch of changes under root that touch a mark — a node added or removed that is or holds a [data-slot], an attribute set on a mark, at any depth — with the node each such change was made in; the answer stops it. The recording renderer observes nothing (the host also walks after mount and update); the DOM’s is a MutationObserver.

Provided Methods§

Source

fn sheet(&self, key: &str, css: &str, on: bool)

FRAME-30: the sheet key (its text css) adopted by the page (on), synchronously, or dropped — document.adoptedStyleSheets, no <link>. The engine calls it once per key each way (it counts the instances).

Source

fn listen_keys(&self, f: Rc<dyn Fn(&Press) -> bool>) -> Unlisten

FRAME-36: calls f with every key press the window hears, in the capture phase, before anything of the page; when f answers true the press is the host’s — preventDefault(), stopPropagation(), stopImmediatePropagation(). The answer stops it. The recording renderer hears nothing (the tests press through App::press).

Source

fn keys_overlay(&self, groups: Option<&KeyGroups>)

FRAME-36: the host’s keys overlay, [data-engine-keys], drawn with groups (every mounted component’s keys), or taken away (none).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§