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

Provide &Dependency to Lazy widget view fn #1646

Merged
merged 1 commit into from
Jan 12, 2023

Conversation

nicksenger
Copy link
Contributor

This is a small ergonomics improvement that I noticed would be beneficial when working with the Lazy widget. The change is just to call the provided view function with a reference to the specified Dependency.

This is useful when the data provided for Dependency originates from the widget tree state, and so we don't have a reference to it which lives for the required 'a lifetime bound on Dependency. In this case we need to take ownership of the data to use it for Dependency. Unfortunately, the provided view function must also satisfy the 'a bound, so the data needs to be cloned again if we want to move it into the view function for use there.

By providing view with a reference to the dependency stored in the lazy widget, we can defer this second clone until the cache is actually invalidated rather than doing it on every view. I think it also makes using Lazy a bit more intuitive.

I'd be happy to write an RFC if more explanation/examples are required to make this change

@nicksenger nicksenger changed the title Provide &Dependency to Lazy widget View Provide &Dependency to Lazy widget view fn Jan 11, 2023
@hecrj hecrj added the feature New feature or request label Jan 12, 2023
@hecrj hecrj added this to the 0.7.0 milestone Jan 12, 2023
@hecrj hecrj added the widget label Jan 12, 2023
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense! Thanks 🙇

@hecrj hecrj merged commit 902131e into iced-rs:master Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request widget
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants