Trait Document

Source
pub trait Document: 'static {
    // Required method
    fn eval(&self, js: String) -> Eval;

    // Provided methods
    fn set_title(&self, title: String) { ... }
    fn create_head_element(
        &self,
        name: &str,
        attributes: &[(&str, String)],
        contents: Option<String>,
    ) { ... }
    fn create_meta(&self, props: MetaProps) { ... }
    fn create_script(&self, props: ScriptProps) { ... }
    fn create_style(&self, props: StyleProps) { ... }
    fn create_link(&self, props: LinkProps) { ... }
    fn create_head_component(&self) -> bool { ... }
}
Expand description

A provider for document-related functionality.

Provides things like a history API, a title, a way to run JS, and some other basics/essentials used by nearly every platform.

An integration with some kind of navigation history.

Depending on your use case, your implementation may deviate from the described procedure. This is fine, as long as both current_route and current_query match the described format.

However, you should document all deviations. Also, make sure the navigation is user-friendly. The described behaviors are designed to mimic a web browser, which most users should already know. Deviations might confuse them.

Required Methods§

Source

fn eval(&self, js: String) -> Eval

Run eval against this document, returning an Eval that can be used to await the result.

Provided Methods§

Source

fn set_title(&self, title: String)

Set the title of the document

Source

fn create_head_element( &self, name: &str, attributes: &[(&str, String)], contents: Option<String>, )

Create a new element in the head

Source

fn create_meta(&self, props: MetaProps)

Create a new meta tag in the head

Source

fn create_script(&self, props: ScriptProps)

Create a new script tag in the head

Source

fn create_style(&self, props: StyleProps)

Create a new style tag in the head

Create a new link tag in the head

Source

fn create_head_component(&self) -> bool

Check if we should create a new head component at all. If it returns false, the head component will be skipped.

This runs once per head component and is used to hydrate head components in fullstack.

Implementors§