Struct mogwai::view::ViewBuilder

source ·
pub struct ViewBuilder {
    pub identity: ViewIdentity,
    pub updates: Vec<MogwaiStream<Update>>,
    pub post_build_ops: Vec<PostBuild>,
    pub view_sinks: Vec<MogwaiSink<AnyView>>,
    pub listeners: Vec<Listener>,
    pub tasks: Vec<MogwaiFuture<()>>,
}
Expand description

An un-built mogwai view. A ViewBuilder is a generic view representation. It is the the blueprint of a view - everything needed to create or hydrate the view.

Fields§

§identity: ViewIdentity

The identity of the view.

Either a name or a tuple of a name and a namespace.

§updates: Vec<MogwaiStream<Update>>

All declarative updates this view will undergo.

§post_build_ops: Vec<PostBuild>

Post build operations/computations that run and mutate the view after initialization.

§view_sinks: Vec<MogwaiSink<AnyView>>

Sinks that want a clone of the view once it is initialized.

§listeners: Vec<Listener>

All event listeners (event sinks)

§tasks: Vec<MogwaiFuture<()>>

Asynchronous tasks that run after the view has been initialized.

Implementations§

Returns whether this builder is a leaf element, ie not a container element.

Create a new container element builder.

Create a new namespaced container element builder.

Create a new node builder.

Adds an asynchronous task.

Add a stream to set the text of this builder.

Add a stream to patch the attributes of this builder.

Add a stream to patch a single attribute of this builder.

Add a stream to patch the boolean attributes of this builder.

Add a stream to patch a single boolean attribute of this builder.

Add a stream to patch the style attribute of this builder.

Add a stream to patch a single style of this builder.

Add a stream to patch the list of children of this builder.

Append a child or iterator of children.

source

pub fn with_post_build<V, F>(self, f: F) -> Selfwhere
    V: View,
    F: FnOnce(&mut V) -> Result<()> + Send + Sync + 'static,

Add an operation to perform after the view has been built.

Send a clone of the inner view once it is built.

Wraps V in AnyView to erase its type until it is built.

Panics

Panics if the AnyView cannot be downcast back into V.

Capture the view and update it using the given update function for each value that comes from the given stream.

The only parameter is a tuple to support being used from the [rsx] macro’s capture:for_each attribute, since the right hand side of such attributes must be a singular Rust expression:

use mogwai_dom::prelude::*;
let (_tx, rx) = mogwai_dom::core::channel::mpsc::bounded::<usize>(1);
let builder = rsx! {
    input(
        type = "text",
        capture:for_each = (
            rx.map(|n:usize| format!("{}", n)),
            JsDom::try_to(web_sys::HtmlInputElement::set_value)
        )
    ) {}
};

And the above RSX is equivalent to the following:

let st = rx.map(|n:usize| format!("{}", n));
let f = JsDom::try_to(web_sys::HtmlInputElement::set_value);
let captured = crate::futures_lite::Captured::default();
let builder = ViewBuilder::default()
    .with_capture_view(captured.sink())
    .with_task(async move {
        let view = captured.get().await;
        while let Some(value) = st.next().await {
            f(&view, value);
        }
    })

Add a sink into which view events of the given name will be sent.

Panics

If the domain specific view cannot be downcast a panic will happen when the boxed view is sent into the sink.

Trait Implementations§

Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.