use crate::message::MessageResult;
use crate::{MessageCtx, Mut, ViewElement, ViewPathTracker};
pub trait ViewMarker {}
pub trait View<State: 'static, Action, Context: ViewPathTracker>: ViewMarker + 'static {
type Element: ViewElement;
type ViewState;
fn build(&self, ctx: &mut Context, app_state: &mut State) -> (Self::Element, Self::ViewState);
fn rebuild(
&self,
prev: &Self,
view_state: &mut Self::ViewState,
ctx: &mut Context,
element: Mut<'_, Self::Element>,
app_state: &mut State,
);
fn teardown(
&self,
view_state: &mut Self::ViewState,
ctx: &mut Context,
element: Mut<'_, Self::Element>,
);
fn message(
&self,
view_state: &mut Self::ViewState,
message: &mut MessageCtx,
element: Mut<'_, Self::Element>,
app_state: &mut State,
) -> MessageResult<Action>;
fn map_state<ParentState, F>(
self,
f: F,
) -> crate::MapState<Self, F, ParentState, State, Action, Context>
where
ParentState: 'static,
Action: 'static,
Context: 'static,
Self: Sized,
F: Fn(&mut ParentState) -> &mut State + 'static,
{
crate::map_state(self, f)
}
fn map_message_result<ParentAction, F>(
self,
f: F,
) -> crate::MapMessage<Self, State, ParentAction, Action, Context, F>
where
ParentAction: 'static,
Action: 'static,
Self: Sized,
F: Fn(&mut State, MessageResult<Action>) -> MessageResult<ParentAction> + 'static,
{
crate::map_message_result(self, f)
}
fn map_action<ParentAction, F>(
self,
f: F,
) -> crate::MapMessage<
Self,
State,
ParentAction,
Action,
Context,
impl Fn(&mut State, MessageResult<Action>) -> MessageResult<ParentAction> + 'static,
>
where
ParentAction: 'static,
Action: 'static,
Self: Sized,
F: Fn(&mut State, Action) -> ParentAction + 'static,
{
crate::map_action(self, f)
}
#[doc(hidden)]
fn check_impl_view(self) -> Self
where
Self: Sized,
{
self
}
}