Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xilem_web: Fix message type of AnyDomView and add .boxed() combinator #460

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion xilem_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ where
}

/// A view which can have any [`DomView`] type, see [`AnyView`] for more details.
pub type AnyDomView<State, Action = ()> = dyn AnyView<State, Action, ViewCtx, AnyPod>;
pub type AnyDomView<State, Action = ()> = dyn AnyView<State, Action, ViewCtx, AnyPod, DynMessage>;

/// The central [`View`] derived trait to represent DOM nodes in xilem_web, it's the base for all [`View`]s in xilem_web
pub trait DomView<State, Action = ()>:
Expand All @@ -97,6 +97,26 @@ pub trait DomView<State, Action = ()>:
type DomNode: DomNode<Self::Props>;
type Props;

/// Returns a boxed type erased [`AnyDomView`]
///
/// # Examples
/// ```
/// use xilem_web::{elements::html::div, DomView};
///
/// # fn view<State: 'static>() -> impl DomView<State> {
/// div("a label").boxed()
/// # }
///
Philipp-M marked this conversation as resolved.
Show resolved Hide resolved
/// ```
fn boxed(self) -> Box<AnyDomView<State, Action>>
where
State: 'static,
Action: 'static,
Self: Sized,
{
Box::new(self)
}

/// See [`adapt`](`core::adapt`)
fn adapt<ParentState, ParentAction, ProxyFn>(
self,
Expand Down