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

send_message to a component from the create method does not work #1222

Closed
3 tasks
aidanhs opened this issue May 13, 2020 · 1 comment · Fixed by #1225
Closed
3 tasks

send_message to a component from the create method does not work #1222

aidanhs opened this issue May 13, 2020 · 1 comment · Fixed by #1225
Assignees
Labels

Comments

@aidanhs
Copy link
Contributor

aidanhs commented May 13, 2020

Problem

Doing link.send_message(Msg::Foo); in the create method of the component silently drops the message

Steps To Reproduce
Apply the following patch (paste it into git apply and hit ctrl+d), then run the todomvc example. I'd expect it to log two things on page load after creating model, but it doesn't.

--- a/examples/todomvc/src/lib.rs
+++ b/examples/todomvc/src/lib.rs
@@ -31,6 +31,7 @@ struct Entry {
     editing: bool,
 }
 
+#[derive(Debug)]
 pub enum Msg {
     Add,
     Edit(usize),
@@ -64,6 +65,9 @@ impl Component for Model {
             value: "".into(),
             edit_value: "".into(),
         };
+        yew::web_sys::console::log_1(&"creating model".into());
+        link.send_message(Msg::Add);
+        link.send_message(Msg::Update("xyz".to_owned()));
         Model {
             link,
             storage,
@@ -72,6 +76,7 @@ impl Component for Model {
     }
 
     fn update(&mut self, msg: Self::Message) -> ShouldRender {
+        yew::web_sys::console::log_1(&format!("got msg: {:?}", msg).into());
         match msg {
             Msg::Add => {
                 let entry = Entry {
@@ -242,6 +247,7 @@ impl Model {
 }
 
 #[derive(EnumIter, ToString, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug)]
 pub enum Filter {
     All,
     Active,

Expected behavior
The message should be scheduled for after the component is mounted. This has changed between 0.12 and 0.16.

Environment:

  • Yew version master
  • Rust version 1.43.0
  • Browser: chromium, firefox

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@aidanhs aidanhs added the bug label May 13, 2020
@jstarry
Copy link
Member

jstarry commented May 14, 2020

Dang, looks like I just introduced this bug on master with #1186

Thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants