Skip to content

Commit

Permalink
feat: put back stateful_component
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanceras committed Apr 2, 2024
1 parent 344d47a commit 5a49e16
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
7 changes: 3 additions & 4 deletions crates/core/src/dom/component/stateful_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ pub fn stateful_component<COMP, MSG, MSG2>(
children: impl IntoIterator<Item = Node<MSG>>,
) -> Node<MSG>
where
COMP: Component<MSG = MSG2, XMSG = ()> + StatefulComponent + 'static,
COMP: Component<MSG = MSG2, XMSG = ()>
+ StatefulComponent
+ Application<MSG=MSG2> + 'static,
MSG: Default + 'static,
MSG2: 'static,
{
/*
let type_id = TypeId::of::<COMP>();
let attrs = attrs.into_iter().collect::<Vec<_>>();

Expand All @@ -173,8 +174,6 @@ where
attrs: attrs.into_iter().chain([mount_event]).collect(),
children: children.into_iter().collect(),
}))
*/
todo!()
}

impl Into<DomAttrValue> for JsValue {
Expand Down
2 changes: 1 addition & 1 deletion examples/experimentals/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Application for App {
//{stateful_component(Button::default(), [], [text!("External child of btn stateful_component: {}", self.click_count)])}
</div>
<div>
//{stateful_component(DateTimeWidget::default(), [],[text("External child of date widget")])}
{stateful_component(DateTimeWidget::default(), [],[text("External child of date widget")])}
</div>
</div>
}
Expand Down
26 changes: 26 additions & 0 deletions examples/experimentals/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ impl Component for Button {
}
}

impl Application for Button
{
type MSG = Msg;

fn init(&mut self) -> Cmd<Msg> {
Cmd::from(<Self as Component>::init(self))
}

fn update(&mut self, msg: Msg) -> Cmd<Msg> {
let effects = <Self as Component>::update(self, msg);
Cmd::from(effects)
}

fn view(&self) -> Node<Msg> {
<Self as Component>::view(self)
}

fn stylesheet() -> Vec<String> {
<Self as Component>::stylesheet()
}

fn style(&self) -> Vec<String> {
<Self as Component>::style(self)
}
}

impl StatefulComponent for Button {
fn attribute_changed(
&mut self,
Expand Down
26 changes: 26 additions & 0 deletions examples/experimentals/src/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,32 @@ where
}
}

impl Application for DateTimeWidget<()>
{
type MSG = Msg;

fn init(&mut self) -> Cmd<Msg> {
Cmd::from(<Self as Component>::init(self))
}

fn update(&mut self, msg: Msg) -> Cmd<Msg> {
let effects = <Self as Component>::update(self, msg);
Cmd::from(effects)
}

fn view(&self) -> Node<Msg> {
<Self as Component>::view(self)
}

fn stylesheet() -> Vec<String> {
<Self as Component>::stylesheet()
}

fn style(&self) -> Vec<String> {
<Self as Component>::style(self)
}
}

impl StatefulComponent for DateTimeWidget<()> {
/// this is called when the attributes in the mount is changed
fn attribute_changed(
Expand Down

0 comments on commit 5a49e16

Please sign in to comment.