Skip to content

Commit

Permalink
xilem_web: Fix message type of AnyDomView and add .boxed() combin…
Browse files Browse the repository at this point in the history
…ator (linebender#460)

I guess I missed this when adding linebender#408, the doc-test should ensure that
`Box<AnyDomView>` is now really a `DomView`.

---------

Co-authored-by: Daniel McNab <[email protected]>
  • Loading branch information
Philipp-M and DJMcNab authored Jul 29, 2024
1 parent a2f1360 commit 1b1a1d3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 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,25 @@ 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()
/// # }
/// ```
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

0 comments on commit 1b1a1d3

Please sign in to comment.