-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
Is your feature request related to a problem? Please describe.
In order to create a component that has a bit of smarts in it, a developer needs to store the props, link, and probably some callbacks and state into the component struct.
Describe the solution you'd like
Each component lifecycle method should pass in a reference to the link and props to alleviate the burden on the developer to store those values themselves.
pub struct Context<COMP> {
link: ComponentLink<COMP>,
props: COMP::Properties,
}
pub trait Component: Sized + 'static {
type Message: 'static;
type Properties: Properties;
fn create(ctx: &Context<Self>) -> Self;
fn mounted(&mut self, ctx: &Context<Self>) -> ShouldRender;
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> ShouldRender;
fn change(&mut self, ctx: &Context<Self>, props: &Self::Properties) -> ShouldRender;
fn view(&self, ctx: &Context<Self>) -> Html;
fn destroy(&mut self, ctx: &Context<Self>) -> ();
}I believe this would also remove the need to have props implement cloneable
hgzimmerman, kellytk, ctaggart, Virgiel, mdtusz and 16 morekellytk, Virgiel, jcornaz and Tanja-4732Tanja-4732