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

Implement Compose for Vec<C> #117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ad-kr
Copy link

@ad-kr ad-kr commented Dec 29, 2024

I've stumbled into an issue where from_iter doesn't update the final compose result/ui when one of the elements in the Iterator changes. Perhaps it is working as intended or is just a bug (issue). In any case, implementing Compose for Vec<C> is a workaround for my issue, as well as being a reasonable implementation in general, in my opinion. Another benefit over using from_iter is that from_iter requires the iterator to implement Data + Clone, while this method does not.

Now, you could do something like this:

#[derive(Data)]
pub struct Something;

impl Compose for Something {
    fn compose(cx: Scope<Self>) -> impl Compose {
        let numbers = [20, 42, 39];

        numbers
            .iter()
            .map(|number| spawn(Text::new(number.to_string())))
            .collect::<Vec<_>>()
    }
}

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 this pull request may close these issues.

1 participant