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§
source§impl ViewBuilder
impl ViewBuilder
sourcepub fn is_leaf(&self) -> bool
pub fn is_leaf(&self) -> bool
Returns whether this builder is a leaf element, ie not a container element.
sourcepub fn element_ns(tag: impl Into<String>, ns: impl Into<String>) -> Self
pub fn element_ns(tag: impl Into<String>, ns: impl Into<String>) -> Self
Create a new namespaced container element builder.
sourcepub fn text<St: Stream<Item = String> + Send + 'static>(
st: impl Into<MogwaiValue<String, St>>
) -> Self
pub fn text<St: Stream<Item = String> + Send + 'static>(
st: impl Into<MogwaiValue<String, St>>
) -> Self
Create a new node builder.
sourcepub fn with_task(self, f: impl Future<Output = ()> + Send + 'static) -> Self
pub fn with_task(self, f: impl Future<Output = ()> + Send + 'static) -> Self
Adds an asynchronous task.
sourcepub fn with_text_stream<St: Stream<Item = String> + Send + 'static>(
self,
st: impl Into<MogwaiValue<String, St>>
) -> Self
pub fn with_text_stream<St: Stream<Item = String> + Send + 'static>(
self,
st: impl Into<MogwaiValue<String, St>>
) -> Self
Add a stream to set the text of this builder.
sourcepub fn with_attrib_stream<St: Stream<Item = HashPatch<String, String>> + Send + 'static>(
self,
st: impl Into<MogwaiValue<HashPatch<String, String>, St>>
) -> Self
pub fn with_attrib_stream<St: Stream<Item = HashPatch<String, String>> + Send + 'static>(
self,
st: impl Into<MogwaiValue<HashPatch<String, String>, St>>
) -> Self
Add a stream to patch the attributes of this builder.
sourcepub fn with_single_attrib_stream<St: Stream<Item = String> + Send + 'static>(
self,
k: impl Into<String>,
st: impl Into<MogwaiValue<String, St>>
) -> Self
pub fn with_single_attrib_stream<St: Stream<Item = String> + Send + 'static>(
self,
k: impl Into<String>,
st: impl Into<MogwaiValue<String, St>>
) -> Self
Add a stream to patch a single attribute of this builder.
sourcepub fn with_bool_attrib_stream<St: Stream<Item = HashPatch<String, bool>> + Send + 'static>(
self,
st: impl Into<MogwaiValue<HashPatch<String, bool>, St>>
) -> Self
pub fn with_bool_attrib_stream<St: Stream<Item = HashPatch<String, bool>> + Send + 'static>(
self,
st: impl Into<MogwaiValue<HashPatch<String, bool>, St>>
) -> Self
Add a stream to patch the boolean attributes of this builder.
sourcepub fn with_single_bool_attrib_stream<St: Stream<Item = bool> + Send + 'static>(
self,
k: impl Into<String>,
st: impl Into<MogwaiValue<bool, St>>
) -> Self
pub fn with_single_bool_attrib_stream<St: Stream<Item = bool> + Send + 'static>(
self,
k: impl Into<String>,
st: impl Into<MogwaiValue<bool, St>>
) -> Self
Add a stream to patch a single boolean attribute of this builder.
sourcepub fn with_style_stream<St: Stream<Item = String> + Send + 'static>(
self,
st: impl Into<MogwaiValue<String, St>>
) -> Self
pub fn with_style_stream<St: Stream<Item = String> + Send + 'static>(
self,
st: impl Into<MogwaiValue<String, St>>
) -> Self
Add a stream to patch the style attribute of this builder.
sourcepub fn with_single_style_stream<St: Stream<Item = String> + Send + 'static>(
self,
k: impl Into<String>,
st: impl Into<MogwaiValue<String, St>>
) -> Self
pub fn with_single_style_stream<St: Stream<Item = String> + Send + 'static>(
self,
k: impl Into<String>,
st: impl Into<MogwaiValue<String, St>>
) -> Self
Add a stream to patch a single style of this builder.
sourcepub fn with_child_stream<St: Stream<Item = ListPatch<ViewBuilder>> + Send + 'static>(
self,
st: impl Into<MogwaiValue<ListPatch<ViewBuilder>, St>>
) -> Self
pub fn with_child_stream<St: Stream<Item = ListPatch<ViewBuilder>> + Send + 'static>(
self,
st: impl Into<MogwaiValue<ListPatch<ViewBuilder>, St>>
) -> Self
Add a stream to patch the list of children of this builder.
sourcepub fn append(self, children: impl Into<AppendArg>) -> Self
pub fn append(self, children: impl Into<AppendArg>) -> Self
Append a child or iterator of children.
sourcepub fn with_post_build<V, F>(self, f: F) -> Selfwhere
V: View,
F: FnOnce(&mut V) -> Result<()> + Send + Sync + 'static,
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.
sourcepub fn with_capture_view<V: View>(
self,
sink: impl Sink<V> + Unpin + Send + Sync + 'static
) -> Self
pub fn with_capture_view<V: View>(
self,
sink: impl Sink<V> + Unpin + Send + Sync + 'static
) -> Self
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
.
sourcepub fn with_capture_for_each<T, V: View>(
self,
(st, f): (impl Stream<Item = T> + Send + Unpin + 'static, impl Fn(&V, T) + Send + 'static)
) -> Self
pub fn with_capture_for_each<T, V: View>(
self,
(st, f): (impl Stream<Item = T> + Send + Unpin + 'static, impl Fn(&V, T) + Send + 'static)
) -> Self
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);
}
})
sourcepub fn with_event<Event: Any + Send + Sync + Unpin + Clone>(
self,
name: impl Into<String>,
target: impl Into<String>,
si: impl Sink<Event> + Send + Sync + Unpin + 'static
) -> Self
pub fn with_event<Event: Any + Send + Sync + Unpin + Clone>(
self,
name: impl Into<String>,
target: impl Into<String>,
si: impl Sink<Event> + Send + Sync + Unpin + 'static
) -> Self
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.