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

Children cannot initiate rerender? #677

Closed
vova616 opened this issue Oct 1, 2019 · 2 comments · Fixed by #698
Closed

Children cannot initiate rerender? #677

vova616 opened this issue Oct 1, 2019 · 2 comments · Fixed by #698

Comments

@vova616
Copy link

vova616 commented Oct 1, 2019

Description

Why does component does not get updated when I return true from update&change?

So I have this component

impl Component for NavLink {
    type Message = Msg;
    type Properties = Props;

    fn create(props: Self::Properties, _: ComponentLink<Self>) -> Self {
        NavLink {
            props: props,
            color: "#454C52".to_string(),
            hover_color: "#888888".to_string(),
            currentColor: "#454C52".to_string(),
        }
    }

    fn update(&mut self, msg: Self::Message) -> ShouldRender {
        match msg {
            Msg::Clicked => {
                self.props.onclick.emit(());
            }
            Msg::StartHover => {
                self.currentColor = self.hover_color.clone();
            }
            Msg::EndHover => {
                self.currentColor = self.color.clone();
            }
        }
        true
    }

    fn change(&mut self, props: Self::Properties) -> ShouldRender {
        self.props = props;
        true
    }
}

impl Renderable<NavLink> for NavLink {
    fn view(&self) -> Html<Self> {
        html! {
            <a style={format!("font-size: 20px; \
                      margin: 0px 10px;\
                      cursor: pointer;\
                      color: {}", self.currentColor)},
               onclick=|_| Msg::Clicked,
               onmouseenter=|_| Msg::StartHover
               onmouseleave=|_| Msg::EndHover >
            {
                if self.props.children.is_empty() {
                    html! {}
                } else {
                    html! {
                        { self.props.children.view() }
                    }
                }
            }
            </a>
        }
    }
}

which should change the color on hover

Expected Results

The color should change immediately

Actual Results

The color changes only when I force update the whole tree

Context (Environment)

  • Rust: nightly
  • yew: v0.9
  • target:wasm32-unknown-unknown
  • cargo-web: vX.X.X
@hgzimmerman
Copy link
Member

At first glance, these issues seem to be related: #641 .

It appears that something is delaying styles from updating by 1 render cycle.

If you put style rules in a class and set the class property instead, then it should update in one cycle. Unfortunately, this makes it hard to parameterize what colors to set your link without in-rust css stylesheet support.

@vova616
Copy link
Author

vova616 commented Oct 1, 2019

Sounds horrible can someone point where the problem might be?

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

Successfully merging a pull request may close this issue.

2 participants